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

sparql-17-4-2-5 query parsed output malformed? #7

Closed
yamalight opened this issue Feb 17, 2015 · 5 comments
Closed

sparql-17-4-2-5 query parsed output malformed? #7

yamalight opened this issue Feb 17, 2015 · 5 comments

Comments

@yamalight
Copy link
Contributor

Not sure here, but maybe there's an issue.

Query looks like this:

FILTER regex(str(?mbox), "@work\\.example$")

Output looks like this

{
  "type": "filter",
  "expression": {
    "type": "operation",
    "operator": "regex",
    "args": [
      {
        "type": "operation",
        "operator": "str",
        "args": [
          "?mbox"
        ]
      },
      "\"@work\\.example$\""
    ]
  }
}

Decoding "\"@work\\.example$\"" turns it into "@work\.example$" which is wrong.
Am I right here? That's a bug?

@RubenVerborgh
Copy link
Owner

In SPARQL literals, \\ is an escape sequence for a single backslash \. Therefore, the string "@work\\.example$" has contents @work\.example$, so the latter is the correct result.

It also makes sense: in example 17.4.2.5 of the SPARQL spec, the purpose of the regex is to match <mailto:alice@work.example>. In other words, the (single) backslash serves to escape the dot.

So the output is correct as far as I understand.

@yamalight
Copy link
Contributor Author

@RubenVerborgh the problem here is that when you unescape "\"@work\\.example$\"" you'll get "@work\.example$" which differs from original SPARQL which looks like "@work\\.example$".
Which means that my generated queries will always be wrong here. So, that does looks like a bug to me. \\ should be escaped to \\\\ during parsing, then when unescaping back it will become \\ which is exactly what was there originally.

@RubenVerborgh
Copy link
Owner

I still think it's the same.

Language Literal in language syntax Interpretation (actual characters inside literal)
SPARQL "@work\\.example$" @work\.example$
JavaScript '"@work\\.example$"' "@work\.example$"

Note how the interpretation is the same in both languages (but the N3.js wraps all literals in double quotes).

In order to convert from the representation to SPARQL, you will need to escape the backslash.

Note that you generally never escape during parsing: parsing means unescaping, generating means escaping. (See for instance how we parse URLs.)

@yamalight
Copy link
Contributor Author

Hmm.. Makes sense! Good, then I'll escape backslashes specifically during query generation.

@RubenVerborgh
Copy link
Owner

Yeah, that's probably something that needs to be done for all literal generation, because backslashes have special meaning.

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

2 participants