Author Topic: Angle Brackets being removed  (Read 2487 times)

TonyLeech

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 76
    • View Profile
Angle Brackets being removed
« on: July 12, 2016, 02:58:20 pm »
I'm testing for special characters today to find out what needs to be escaped or url encoded, but I don't know how to handle what I found.

If I include angle brackets in a cell then the displayed content of the cell changes.

Example 1: If I put a tag-style word into a grid cell then it disappears from the display altogether.  Although the full word still exists and is sent/received by JSON to the database.  Try putting this text into a grid cell to see what I mean - "Enter this <text> like this".  If you put that small phrase into a grid cell you notice that the <text> word disappears from display altogether.

Example 2: If I put a lt sign (<) into a grid cell followed directly by more text then all the subsequent text vanishes.  Try putting this text into a grid cell to see what I mean - "Enter this <text into cell".  If you put that small phrase into a grid cell you notice that everything to the right of the < sign is removed leaving only "Enter this ".

You can try both of these examples in your own batch editing demos.

Can you explain to me what is actually happening with these examples and suggest where I can add an escape character or other encoding to make sure all text is displayed?

Many thanks for your help

TonyLeech

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 76
    • View Profile
Re: Angle Brackets being removed
« Reply #1 on: July 12, 2016, 06:09:33 pm »
Ok, so after I worked out it was an HTML browser issue and not a javascript grid issue I solved it with render.  Does this look like the right way to solve it...

         render: function(ui) {
            var strPartName = ui.cellData;
            strPartName = strPartName.replace(/</g, "&lt;");
            strPartName = strPartName.replace(/>/g, "&gt;");
            return strPartName;
         }

Thanks and regards

Tony

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6263
    • View Profile
Re: Angle Brackets being removed
« Reply #2 on: July 13, 2016, 03:02:16 pm »
Tony

Grid doesn't modify the markup in any way, it displays it as such. So all the rules which apply to escaping HTML tags in a web page ( document ) apply without any grid specific considerations.

if <b>Hello World</b> is to displayed literally, it would be &lt;b&gt;Hello World&lt;/b&gt;

< is to replaced by &lt; and > by &gt; as you have already mentioned in your post. I don't have much to add here :)