Search code examples
sapui5abap

Can't unescape escaped string with ABAP


I want to escape this string in SAPUI5 like this.

var escapedLongText = escape(unescapedLongText);

String (UTF-8 quote, space, Unicode quote)

" “

Escaped string

%22%20%u201C

I want to unescape it with this method, but it returns empty. Any ideas?

DATA: LV_STRING TYPE STRING.

LV_STRING = '%22%20%u201C'.

CALL METHOD CL_HTTP_UTILITY=>UNESCAPE_URL
  EXPORTING
   ESCAPED   = LV_STRING
RECEIVING
    UNESCAPED = LV_STRING.

Solution

  • I changed the code in SAPUI5 to the following:

    var escapedLongText = encodeURI(unescapedLongText);
    

    This results in: (like andreas mentioned)

    %22%20%e2%80%9c

    If I want to decode it later in SAPUI5, it can be done like this:

    var unescapedLongText = unescape(decodeURI(escapedLongText));
    

    The unescape needs to be done, because commas (for example) don't seem to be decoded automatically.