I have a form fields that allows admins to update the headers & Footers of their site and for the most part it works awesome.
Where is falls apart is anytime there is a double apostrophe with no space.
Here is the stock Tag Manager:
<!-- Google Tag Manager -->
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s),
<!-- End Google Tag Manager -->
On this line:
The 2 apostrophes, when saved in SQL come back as 1 - somewhere in the SQL process one of them is being stripped?
This only happens when there are 2 apostrophes in a row with nothing between them.
How do I fix this?
I would need to see the query tag/call that you are making. I'm guessing you're doing something like:
set [somecolumn] = '#form.value#'
where [someothercolumn] = 123
If this is the case, changing you query to something like the following should do the trick:
set [somecolumn] = <cfqueryparam value='#form.value#' cfsqltype='CF_SQL_VARCHAR' />
where [someothercolumn] = <cfqueryparam value='123' cfsqltype='CF_SQL_INTEGER' />
That's because SQL uses the apostrophe to delimit string values.
WHERE uname = 'john'
If an apostrophe needs to be part of the value of the string, then it needs to be escaped.
WHERE businessname = 'Jack''s Pizza'
CF will, I believe, automatically escape the apostrophe before it gets to the database.