Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot include escaped doublequote character in string #223

Open
skyrod-vactai opened this issue Dec 31, 2023 · 8 comments
Open

Cannot include escaped doublequote character in string #223

skyrod-vactai opened this issue Dec 31, 2023 · 8 comments

Comments

@skyrod-vactai
Copy link

According to the docs:

Strings can be typed in the same way as they do in JSON using double quotes "", with the same escape rules.

And from the tutorial:

The input literal representations are similar to those in JavaScript.
In particular, strings in double quotes are guaranteed to be interpreted in the same way as in JSON. 

JSON rules do allow \" and serde_json produces JSON with that sequence. But cozo doesn't accept it:

=> ?[foo] <- [["blah\"\""]] 
parser::pest

  × The query parser has encountered unexpected input / end of input at 19..19

I ran into this while trying to insert data. What I did was format the row data as JSON, and spliced that into a generic query that does a :put. If there's a better way to insert data let me know. I know you can import an entire JSON file but I want something I can call from my program (I'm using the cozo library in a rust program).

@Volland
Copy link

Volland commented Dec 31, 2023

Screenshot 2023-12-31 at 19 46 41 yep \" is not working

@aramallo
Copy link

aramallo commented Feb 8, 2024

There is another issue with strings. I've tried avoiding the problem reported here by using raw string notation e.g. ___"I'm a raw string"___. But this will fail when a hash char (#) is included in the string.

The following example will FAIL with reason The query parser has encountered unexpected input / end of input at 58..58

?[repository_uri, oid, data, size] <- [['test', '000', ___\"John said  'I like color #298594'\"___, 30]]
:put blob {repository_uri, oid => data, size}

Just removing the # char makes it work.

I am guessing this might be because Rust uses # instead of _ for raw strings?

The combination of the issue reported by @skyrod-vactai and this makes it impossible to store arbitrary strings in CozoDB. For example storing JSON, HTML, CSS, XML, SVG and any other source code that typically contains multiple instances of double, single quotes and the hash char.

The following simpler example will also fail

?[repository_uri, oid, data, size] <- [['test', '000', ___\"#298594\"___, 8]]
:put blob {repository_uri, oid => data, size}

@aramallo
Copy link

aramallo commented Feb 8, 2024

I just reported this as a separate issue in #234

@Volland
Copy link

Volland commented Mar 2, 2024

@aramallo @skyrod-vactai i figure out workaround - if i pass strings as params to a query it is works . so you could use variables binded to a query params - it is working well

@aramallo
Copy link

aramallo commented Mar 2, 2024

Do you mind posting an example here? Thanks a lot @Volland

@aramallo
Copy link

aramallo commented Mar 2, 2024

BTW the solution I posted works on the parser online playground (which I guess uses the latest version) but not when used inside coso, I need to check upgrading the parser lib version in cozo and doublecheck

@Volland
Copy link

Volland commented Mar 3, 2024

@aramallo sure
So
query like
?[id , label] := *nodes[id, label], label in [ '" boom "'] will fail
I move it to a param
?[id , label] := *nodes[id, label], is_in(label , $list) where {list : [ '" boom "']}

@aramallo
Copy link

aramallo commented Mar 3, 2024

Ah nice thanks @Volland !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants