Coder Social home page Coder Social logo

Comments (8)

gregsdennis avatar gregsdennis commented on June 11, 2024 1

I'll use this issue, thanks.

from json-everything.

gregsdennis avatar gregsdennis commented on June 11, 2024

Hey there. You can use double quotes for the string.

$[?(@.Name == "how do I escape a single' quote here?")]

Then you don't need to escape it.

Otherwise, you'll use a backslash \ to escape.

from json-everything.

ashek-simeon avatar ashek-simeon commented on June 11, 2024

Thank you so much for responding, and for all the work you do on this amazing library!

I think the escaping may not be working for single quotes in strings surrounded by single quotes, since this fails to parse

$[?(@.Name == 'how do I escape a single\' quote here?')]

image

Also, the string I am working with may contain single quotes or double quotes (it is dynamic), so I may still have to use escaping if I use double quotes to surround the string. Good news is -- escaping seems to be working as expected for double quote strings.

Do you think I should open a new issue with a type of "bug" for parsing failing with the escaped single quotes?

from json-everything.

He-Pin avatar He-Pin commented on June 11, 2024

This is a bug and the parser need to do an escaping, I'm currently parse strings to a seq[String] and then call a mkString to get the final result string.

I think this issue can be added to the test suite too.

        final JsonPathAST.JsonPathQuery query = JsonPath.parseQuery("$['how do I escape a single\\' quote here?']");
        Assertions.assertEquals("how do I escape a single' quote here?",
            ((Selector.NameSelector) query.segments().get(0).selection().selectors().get(0)).name());

image

from json-everything.

gregsdennis avatar gregsdennis commented on June 11, 2024

This is a bug

Yes, as labeled.

from json-everything.

gregsdennis avatar gregsdennis commented on June 11, 2024

The test suite has these two tests which seem to confirm I do handle them. I wonder what the difference is between being able to handle these and not being able to handle your case:

{
  "name": "name selector, single quotes, escaped single quote",
  "selector": "$['\\'']",
  "document": {
    "'": "A"
  },
  "result": [
    "A"
  ]
},
{
  "name": "name selector, single quotes, escaped reverse solidus",
  "selector": "$['\\\\']",
  "document": {
    "\\": "A"
  },
  "result": [
    "A"
  ]
}

Might be that yours is in an expression and these tests are in selectors, but I'd expect that uses the same parsing code...

from json-everything.

gregsdennis avatar gregsdennis commented on June 11, 2024

It doesn't! I'm going to add this to the test suite and then fix it here.

from json-everything.

ashek-simeon avatar ashek-simeon commented on June 11, 2024

It doesn't! I'm going to add this to the test suite and then fix it here.

Thank you so much!

from json-everything.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.