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

.toString() with special chars throws #75

Open
rkaw92 opened this issue Aug 24, 2016 · 0 comments
Open

.toString() with special chars throws #75

rkaw92 opened this issue Aug 24, 2016 · 0 comments

Comments

@rkaw92
Copy link

rkaw92 commented Aug 24, 2016

Hi,
I'm trying to "unparse" an RQL expression - restore it to its textual form. To this end, I'm constructing a Query object seeded with the raw result of the parsing:

const query = require('rql/query');
const parser = require('rql/parser');
const parsedTree = parser.parse('eq(name,%25Potatoes%25)');
(new query.Query(parsedTree)).toString();

In the nominal case of no special chars, it works just fine - however, as presented above, an error will be thrown:

/home/thewanderer/Devel/Node/rql-test/node_modules/rql/parser.js:218
                        string = decodeURIComponent(string);
                                 ^

URIError: URI malformed
    at decodeURIComponent (native)
    at Object.exports.converters.auto (/home/thewanderer/Devel/Node/rql-test/node_modules/rql/parser.js:218:13)
    at Object.exports.encodeValue (/home/thewanderer/Devel/Node/rql-test/node_modules/rql/query.js:82:43)
    at queryToString (/home/thewanderer/Devel/Node/rql-test/node_modules/rql/query.js:66:18)
    at serializeArgs (/home/thewanderer/Devel/Node/rql-test/node_modules/rql/query.js:43:16)
    at queryToString (/home/thewanderer/Devel/Node/rql-test/node_modules/rql/query.js:62:7)
    at serializeArgs (/home/thewanderer/Devel/Node/rql-test/node_modules/rql/query.js:43:16)
    at Query.toString (/home/thewanderer/Devel/Node/rql-test/node_modules/rql/query.js:50:3)
    at Object.<anonymous> (/home/thewanderer/Devel/Node/rql-test/rubbish.js:4:31)

This is probably because the Query object takes args verbatim and, during stringification, checks whether the "converted" form is the same as the input before deciding whether to apply a type prefix (turns something into string:something) . However, this uses the parser's converter, which, instead of encoding the contents, decodes it - the converter is one-way only. I consider this a logic bug.

@rkaw92 rkaw92 changed the title Unparsing with special chars .toString() with special chars throws Aug 24, 2016
rkaw92 added a commit to greatcare/rql that referenced this issue Aug 24, 2016
This change enables converting values containing special characters, such as the percent sign (%), to strings, by always encoding values for which the check if encoding is actually necessary has failed.
For values containing URI escape characters, the check throws an error (because they are not decodable), but we still need to encode them.

Fixes persvr#75
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

1 participant