0

I have a div containing a string which is a Cypher query:

<div id="foo">match (n)-[r]-() where n.gid='Cx' return n,r</div>

Since the ' character will be encoded as &#8217;, and since Cypher query isn't able to automatically decode it, I need to make sure whether the ' character I see (and Cypher sees as well) is really the ' character, not just &#8217; but the browser automatically transforms it to '.

In all the places the character is always showed as '; the only place it's really show its true evil is in the HTML view-source page. I try using a solution from What's the right way to decode a string that has special HTML entities in it?:

function decodeHtml(html) {
    var txt = document.createElement("textarea");
    txt.innerHTML = html;
    return txt.value;
}

But Cypher still doesn't accept it. But I guess I cannot check when the string is still encoded or not, because anywhere I go, the browser will always show the decoded version.

Another problem is when I add this into the console:

string = document.getElementById('foo').innerText
string.includes("'") //false
string.includes("&") //false

If it return false in both case, then what exactly the version of the character in there? Is it the decoded or encoded version?

Related: Can Cypher interpret HTML character codes as input?

Ooker
  • 1,969
  • 4
  • 28
  • 58
  • Why exactly is a plain single-quote character being encoded like that? – Pointy Jan 04 '22 at 17:31
  • The `
    ` as posted in your question has plain ordinary single-quote characters.
    – Pointy Jan 04 '22 at 17:37
  • I have no idea. I copy exactly what's in the script and the output – Ooker Jan 04 '22 at 17:39
  • 1
    If you're copy/pasting from some online resource, then that's your problem. It is not uncommon for that to happen. Just re-type the content manually in your own text editor or IDE. – Pointy Jan 04 '22 at 17:43
  • No, the input string in the div is typed manually and it should work with Cypher – Ooker Jan 04 '22 at 17:50
  • Well then the culprit is your own IDE. Single-quote characters have the code `'`. If you're getting something else, then your editor or IDE is putting them there. – Pointy Jan 04 '22 at 17:51
  • @Pointy you are right. The IDE in here is actually WordPress. I check that and somehow my PHP/WordPress setup decides to convert the characters, and the output of the HTML page is indeed doesn't work with Cypher. Anyway, using the [HTML entity tool](https://mothereff.in/html-entities#match%20%28n%29-%5Br%5D-%28%29%20where%20n.gid%3D%27Cx%27%20return%20n%2Cr) I see that the correct code should be `'`? Although `'` still works. Are there two versions of HTML entity encoding? – Ooker Jan 04 '22 at 22:25
  • But anyhow, I guess the main problem still remains: if the string is still encoded, then Cypher won't accept it – Ooker Jan 04 '22 at 22:33

0 Answers0