Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts

    Question REreplace dynamic backreference

    Hello, everyone.

    It's been a while since I was last here. Surprised by the new appearance. Not sure if I like it.. still getting used to it. :)

    I'm banging my head into a wall and could use some advice on code.

    I'm attempting to take a string that has been 'cleansed' (ie, HTML tags removed, certain characters replaced with ASCII code, etc.) and I'm trying to replace the ASCII codes with the character/symbol they represent.

    For example, if " or &##8220; or &##8221; is found, replace all with a standard double-quote.

    So with the above examples, I'm creating a list of replacements for the lettered codes (") which will be tedious. But I'm trying to automate the numerical ASCII codes replacement with #chr(n)# and it's not working.

    Code:
      new_string = trim(arguments.ascii_string);
      new_string = REreplace(new_string,"&##(\d+);","chr(\1)","all");
    The above code will display chr(number). But if I try to use the output tags, it fails. I've tried many different variations (more than the one, below).
    Code:
      new_string = trim(arguments.ascii_string);
      new_string = REreplace(new_string,"&##(\d+);","#chr(\1)#","all");
    Is there a way to get the backreference to work with dynamic code???

    OR - is there a better way to revert ASCII to character/symbol?

    Thanks,
    Last edited by WolfShade; 02-27-2014 at 03:13 PM.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #2
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts

    Lightbulb THERE IS a better way..

    Found it! Turns out this is a question I asked a while ago on Adobe forums (I completely forgot about it), and someone replied with an excellent solution.

    But you have to have ESAPI. CF 9.0.2 with all hotfixes, or CF10, is required.

    12Robots first informed me that what I'm trying to convert is not ASCII, but HTML Entity encoding. SO.. with that in mind..

    Code:
              <cfset string = "&lt;hi&gt;" />
     
              <cfset list = createObject("java", "java.util.ArrayList") />
              <cfset htmlCodec = createObject("java", "org.owasp.esapi.codecs.HTMLEntityCodec") />
              <cfset list.add(htmlCodec) />
              <cfset encoder = createObject("java", "org.owasp.esapi.reference.DefaultEncoder").init(list) />
     
              #string#
              <br />
     
              #encoder.decodeForHTML(string)#
    Now, I just hope that the production environment is running ESAPI, as well, or this was a complete waste of time.

    UPDATE: Production is not running either 9.0.2 or 10, so I'm back to my original issue. Any suggestions greatly appreciated.
    Last edited by WolfShade; 02-27-2014 at 03:15 PM. Reason: Can't find how to mark this RESOLVED.
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •