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

Bug: Non-Alphanumeric characters in property names breaks the lib #14

Open
julius-e opened this issue May 14, 2019 · 1 comment
Open

Comments

@julius-e
Copy link

I have columns in my database with . characters in them. named-placeholders breaks when I pass it objects that contain non-alphanum chars in their property names.

i.e.

{
  "my.funky.col.id": 1234
}

The following is a change I made to the param regex that seems to have addressed my specific issue:

const RE_PARAM = /(?:\?)|(?::(\d+|(?:[a-zA-Z][a-zA-Z0-9_]*)))/g

to

const RE_PARAM = /(?:\?)|(?::(\d+|(?:[a-zA-Z][a-zA-Z0-9_\.]*)))/g, // I added \. to the regex

My question is, how should named-placeholders handle non-alphanum chars in column names, since MySQL allows them as long as they're escaped with backticks? Currently RE_PARAM is private, and it seems that there is no one-size-fits-all regex. Expose it as an option on createCompiler?

I saw you changed the regex in #6 so maybe that is the way you want to go with this. Please advise. I'm ready and willing to submit a PR.

Full repro of issue:

var namedPlaceholders = require("named-placeholders")
var np = namedPlaceholders();
np('select * from test where `my.funky.col.id` = :my.funky.col.id', {"my.funky.col.id": 1234})

Returns

["select * from test where `my.funky.col.id` = ?.funky.col.id", [undefined]]
julius-e pushed a commit to julius-e/named-placeholders that referenced this issue May 14, 2019
@pineshmenat
Copy link

pineshmenat commented May 19, 2020

In regards to the above issue where @julius-e had '.' in his column, I am facing similar issue where I have '-' in my column , I faced the same issue with error as Bind parameters must not contain undefined. because of RE_PARAM regex could not parse my name place holder having '-'. So I add - to the regex and it worked!,

const RE_PARAM = /(?:\?)|(?::(\d+|(?:[a-zA-Z][a-zA-Z0-9_\.\-]*)))/g, // I added \- to the regex

I think we should build one powerful regex to include/match any random char which might break the lib.

What you guys think?

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