orientdb icon indicating copy to clipboard operation
orientdb copied to clipboard

Escaping backslashes and newlines in strings has problems

Open mrft opened this issue 12 years ago • 10 comments

The whole explanation can be found in this thread: https://groups.google.com/forum/#!topic/orient-database/znZhid64EjU

Trying to store newlines in a property, I tried things like

UPDATE MyClass set mytext = 'Hello\nWorld' and UPDATE MyClass set mytext = "Hello\nWorld" but no luck. insert into MyClass content { key: 1, mytext: "Hello\nWorld" } does work as expected...

Then I thought I found a workaround using the MERGE command update V merge { "value2": "Hello\nWorld! Backslash = \ " } where key = "x"

BUT there are other strange issues with escaped BACKSLASHES! The following FAILS with java.lang.IllegalStateException: Missing closed string character: '"', position: 75 update V merge { "value2": "Backslash = \" } where key = "x" while this seems to work (added a space character at the very end) update V merge { "value2": "Backslash = \ " } where key = "x"

but when I want to update a javascript function, I have to escape each backslash twice !!!

The following will not behave as expected update OFunction merge { code : "// \/\/" } where name = 'testBackslashInComment'

A select query on the database will return "code": "// //" instead of the expected "code": "// \/\/"

But the following query update OFunction merge { code : "// \\/\\/" } where name = 'testBackslashInComment' will produce "code": "// \/\/"

But using SET instead of MERGE, we get: update OFunction set code = "// \/\/" where name = 'testBackslashInComment' we get the expected "code": "// \/\/"

(but then we are back to the \n not working...)

mrft avatar Jun 04 '14 07:06 mrft

Is this still valid against 1.7.8 or majors?

lvca avatar Aug 28 '14 10:08 lvca

Yes, the bug still exists. This is most annoying for javascript functions (since it will damage regular expressions using \ for escaping a special char, or javascript strings containg \n, and comments etc. )

Simple test:

go to studio, and try to save a function with the folowing code

// \/

will become after saving

// /

mrft avatar Aug 30 '14 11:08 mrft

Is this fixed? I'm not running into this anymore since c0af38b.

AaronSchulz avatar Dec 31 '14 10:12 AaronSchulz

maybe my last commit also fixed this, it would be really good news. I'm going to check it

luigidellaquila avatar Dec 31 '14 13:12 luigidellaquila

Yes, it's fixed too. @maggiolo00 could you take a final look at this (regarding Studio functions, maybe I'm missing something) and in case close it?

Thanks

luigidellaquila avatar Dec 31 '14 13:12 luigidellaquila

@luigidellaquila i've checked on this https://github.com/orientechnologies/orientdb-studio/issues/75 and it is fixed

wolf4ood avatar Dec 31 '14 13:12 wolf4ood

I'm still experiencing this problem in a different form. All my latex equations are stripped of backslashes. Example: "\frac{2}{3}" is stripped to "rac{2}{3}". The worst thing is that I have little control over the data source

stanonyime avatar Mar 13 '15 14:03 stanonyime

I also have trouble escaping. I can't find a clear definition of how it is supposed to work. Can someone give me list of characters that need to be escaped inside a single-quoted string in an SQL-query and how to escape them?

omgold avatar Jun 16 '15 06:06 omgold

This is still an issue. It should not be closed

ErikShiken avatar Feb 07 '17 15:02 ErikShiken

This comment helped me https://github.com/orientechnologies/orientdb/issues/5469#issuecomment-164777360

spanyukov avatar Jan 24 '18 21:01 spanyukov