.toString() with special chars throws
- Dominant language
- JavaScript
- Stars
- 276
- Forks
- 48
- PR merge metrics
- No merged PRs in 30d
Description
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:
``` js
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. (/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.
Contributor guide
Assessment
This issue has not been assessed yet.