Skip to content

Missed substitutions from single quotes in comments #9

Open
@danfike

Description

@danfike

When you attempt to do named-placeholders substitutions on SQL strings containing comments with odd numbers of single quote characters, things go awry. I'd guess that, during parsing, the single quote is probably pushing a state on the stack that it shouldn't, since we're in a comment.

Here's an easy example to reproduce

var resolve = require('named-placeholders')();
var sqlq = `
    SELECT :foo AS foo
    UNION ALL
    -- dan's comment
    SELECT :foo AS foo
    UNION ALL
    -- dan's other comment
    SELECT :foo AS foo
`;
var resolvedQuery = resolve(sqlq, {'foo': 'woof'});
console.log(resolvedQuery[0]);

Notice the failed substitution in the second SELECT:

    SELECT ? AS foo
    UNION ALL
    -- dan's comment
    SELECT :foo AS foo
    UNION ALL
    -- dan's other comment
    SELECT ? AS foo

Observed using named-placeholders version 1.1.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions