Skip to content

.toString() with special chars throws #75

Description

@rkaw92

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions