Hi D@viiid,
I agree with Hermann (of course :-) )
When your url is test%2525
, the first decode result will be test%25
(the %25
is changed to simply the %
), and then the 2nd decode result will be test%
, but if you only had test%25
, then the first decode will result in test%
, but that naked percent with nothing following is illegal for the 2nd decode, which fails with
Invalid url in dp:decode 'test%'
Even if that wasn't at the end of the string, no telling if %xx
would do something or fail. If those two following characters happen to be valid hex and hopefully a valid utf-8 character it might work, but you'd get the same error as above if you had test%25test
, ie what followed the %
was not valid 2 digit hex, for example
Invalid url in dp:decode 'test%test'
Since there is no catching of this xslt runtime error, you'll need to test for it prior to doing the decode. Hermann provided a contains example, but if you're really getting dynamic data where you are not necessarily getting a %2525, you may also need to revert to a regular expression that would match any % and a non two digit hex character and not attempt the decode if you find one of those, perhaps a regular expression test with
regexp:test($stringtodecode, '%(?!([0-9|A-F][0-9|A-F]))')
which will return a match if it finds any percent character not followed by two hex digits, including the percent character at the end of a string.
Regards,
Steve
------------------------------
Steve Linn
Senior Consulting I/T Specialist
IBM
------------------------------
Original Message:
Sent: Wed February 28, 2024 03:58 AM
From: D@viiid
Subject: dp:decode('test%11',url)
Hello Steve
sorry for confusion : yes my example is not relevant.
What i received is 'test%2525´ and in this case I had to double escape (first to pass from %2525 to %25, second to pass from %25 to %)
but since couple of Week, I also receive %25. (Or other caracters escape only on Time)
In my code, i used a couple of dp:decode and it works fine for %2525 but not for %25.
Is it more clear ?
maybe I can use gw function call from my stylesheet to decode string and use try/catch to avoid error and continue process in the stylesheet
what do you mean ?
:)
------------------------------
D@viiid
Original Message:
Sent: Tue February 27, 2024 04:24 PM
From: Steve Linn
Subject: dp:decode('test%11',url)
Hi D@viiid,
First, the 2nd argument to the dp:decode is a string, so your statement should have url in single quotes as a string literal
<xsl:variable name="decodedUrl" select="dp:decode('test%11','url'
)"/>
After this is done, I logged to the console the string-length($decodedUrl) and received an answer of 5, so the decode did work. Now a %11 in ascii is actually a DC1 (Device Control 1 - x11), but my question is why are you having any invalid ascii character %11 in the url string to be decoded??? By the way, don't try to write that variable to the console as a x11 causes a failure of the logging subsystem and thus the xslt will get a runtime error. If I change that value to have a valid ascii character I would expect to see in a url, say %2B (a + character), then the decoded string is test+
as expected.
Bottom line, dp:decode, assuming the 2nd argument is properly specified, is translating %xx to the associated ascii xx character and is not failing, but the character it is translating may cause the logging system heartburn if you try to do an xsl:message and write its value to the default logs. What is your use case that %11 is trying to handle?
Regards,
Steve
------------------------------
Steve Linn
Senior Consulting I/T Specialist
IBM
Original Message:
Sent: Tue February 27, 2024 05:51 AM
From: D@viiid
Subject: dp:decode('test%11',url)
Hello
Just a quick question about this command : dp:decode('test%11',url)
This command thrown an error because the % is not escaped (%25 expected)
Is there a way to catch this error and avoid to have an error rule triggered ?
Some time client send double escapement (%25C3%25A9 first decode--> %C3A9 seconde decode --> é) but sometime, client just send %c3a9.
So it will be nice if dp:decode can be catched in case of failure
Any workaround ? thanks :)
------------------------------
D@viiid
------------------------------