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

Does addEntry work with toString? #23

Open
louischoi opened this issue Jan 2, 2019 · 4 comments
Open

Does addEntry work with toString? #23

louischoi opened this issue Jan 2, 2019 · 4 comments

Comments

@louischoi
Copy link

When trying the mentioned functions with quotes, I am confused where I thought the mixed quotes would be preserved after parsing the stringified query. Is the following behavior intended? or I simply misused the functions?

var SearchString = require("search-string")
const str1 = "";
const searchString1 = SearchString.parse(str1);
searchString1.addEntry('from', '\'"\'"', false);
console.log(searchString1.getConditionArray()[0].value) // '\"'\"

const str2 = searchString1.toString();
const searchString2 = SearchString.parse(str2);
console.log(searchString2.getConditionArray()[0].value) // \"\"
@ttacon
Copy link
Contributor

ttacon commented Jan 3, 2019

This looks like the quotes are preserved in the first example to me?

var SearchString = require("search-string")
const str1 = "";
const searchString1 = SearchString.parse(str1);
searchString1.addEntry('from', '\'"\'"', false);
console.log(searchString1.getConditionArray()[0].value) // '\"'\"

const val = searchString1.getConditionArray()[0].value;
console.log(val.length) // 4.

Let me know if this isn't what you expected? The first string is preserved.

@louischoi
Copy link
Author

louischoi commented Jan 3, 2019

@ttacon Oh sorry for the confusion, the strings are not separate, I only have issue on searchString2 (because I somehow can't .parse() a string with mixed quotes directly so I used this approach to parse it).

...
searchString1.addEntry('from', '\'"\'"', false); // a length 4 string
...
console.log(searchString2.getConditionArray()[0].value) // \"\"
console.log(searchString2.getConditionArray()[0].value.length) // 2

Edit: I would expect the length of searchString2.getConditionArray()[0].value is still 4

@ttacon
Copy link
Contributor

ttacon commented Jan 4, 2019

Ah, my apologies for not clearly reading the second example 😅. I believe that this is currently functioning as intended (treating the initial nested " as a token and then appending the last one, thus stripping the single quotes). Definitely interested to hear more if you have a use-case that needs this preservation of quoting?

@louischoi
Copy link
Author

I'm trying to follow

treating the initial nested " as a token and then appending the last one, thus stripping the single quotes

Would you mind walking me another example?

let searchString = SearchString.parse(`to:a"b'"c'`); // 7 characters, 2 single quotes, 1 in between, 1 at last
console.log(searchString.getConditionArray()[0].value); // ab'c

Ultimately I wish to see a"b'"c', and I can understand if it shows up as either ab'c' or even abc (by eliminating quote pairs). But now I'm scratching my head because I'm actually seeing ab'c, in which the double quote pair disappears along with the single quote at the last position. Why is the single quote in between the string got preserved but not the last one?

Speaking of use-cases, I plan to use the search keywords to perform character-by-character exact match searching, so if a document actually contains quote pairs, I might not be able to find it when my query string include those quotes. That being said, I could just avoid typing the whole sentence, but the inner phrase instead to workaround this.

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