Forum Discussion

keithkelly's avatar
2 years ago

Colons are sometimes escaped...?

A user reported this, and sure enough

 

This happens both in & out of code blocks, and not necessarily just after javascript. 

I submitted a support ticket, but I'm posting here too because I found it very odd that this issue is scattered around the Khoros community as well (search "colon" and you'll see this error all over the place)

Has anyone else experienced this and/or resolved it?

  • It seems like the colon bug only happens after the word j-a-v-a-s-c-r-i-p-t is used (without dashes). Watch:

    jav:ascript

    :javasc

    javasc:

    java:script

    javascript:

    java:script

    javasc:

    :javasc

    jav:ascript

    • keithkelly's avatar
      keithkelly
      Leader

      whelp, in the above, only the instance after the word "javascript" was replaced.  Got an error saying "invalid html was found, so we fixed it for you."  Still, annoying to not be able to post javascript code.

      But in our community, it replaces all instances of the colon after the word JavaScript is first used. 

  • Interesting, I have seen this elsewhere, I believe it was in the SEO description field on a post page or something like that, when saving it would double-encode the ampersand "&" and thus create a mess, because that encoded entity would have an ampersand again, e.g. "&", which would then become "&" and it would get longer and longer with every save of the article/post ending up in "&amp", you get the picture 😜.

    So i do believe what is at play here is a similar problem, the post was created containing a colon ":", when saved, that was encoded as ":", then the post was edited (that's where the theory begins) and when saving that edit, the ampersand of the ":" HTML entity was encoded as "&", rendering that first HTML entity not an entity anymore by turning it into ":", get it?

    Here's some support for that theory:

    https://community.khoros.com/t5/Developer-Discussion/JavaScript-in-custom-content/m-p/93590

  • Double posting to prevent that exact bug form happening to my post above 😉...

    So the issue is that the content encoder Khoros uses is a bit dumb, it just checks character by character and does not check if an ampersand is part of an already encoded HTML entity... not sure if that is something we can fix, other than using JavaScript (which I did to solve the problem in the SEO field, but i should probably re-visit that code and expand it to all content...) on the editor Pages and un-encode any existing "&" into "&" within form fields...

    This is the code i used for that (which i need to update it seems):

     

    // Handle &amp ampersand bug in SEO field of Article (TKB, more?) Editor Pages
    // & get replace with & but each time the article is saved again, the & of the &
    // gets encoded again, resulting in continuous encoding, e.g. &
    if ( $('.lia-form-message-seo-description-input, .lia-form-message-seo-title-input').length ) {
    	$('.lia-form-message-seo-description-input, .lia-form-message-seo-title-input').each(function() {
    		$(this).val($(this).val().replaceAll(/amp;/gm, ''))
    	});
    }

     

     

  • maybe in the content field the rule is more lax?

  • it's just to keep you safe! ğŸ˜‚😜