sidorares / sidorares/node-mysql2
mysql2/promise escaping apostrophes on insert
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 4.4k
- Forks
- 680
- Avg merge
- 9h 7m
- Merged PRs (30d)
- 59
Description
I am running into an issue where I am setting a variable to JSON.stringify() and then inserting that as the value into a JSON column in the database.
Here is the variable value before the insert statement (statement is trimmed):
{"56":"Describe any cramping or pain you may have<br><br><br><br>blank line then new line's here","57":"Yes","58":"pain at any other time<br><br>next line's<br><br><br><br>blank lines then next"}
And then, after the insert statement, it looks like this:
{"56":"Describe any cramping or pain you may have<br><br><br><br>blank line then new line\'s here","57":"Yes","58":"pain at any other time<br><br>next line\'s<br><br><br><br>blank lines then next"}
If you'll look at 56, 58 (and there are others) you'll notice that in the variable value before the insert the apostrophes are not escaped; however, on the insert they are.
What am I missing here?
I appreciate anyone's assistance.
TIA!
Jason
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No source file, test, or complete INSERT statement is identified. Start by reducing the JSON-column insert to a minimal mysql2/promise reproduction and compare the stored value with the value returned by a read. Done means documenting whether the backslashes are only a display or storage representation, or confirming a reproducible escaping bug.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mysql, node.js
- Domain
- database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100