Skip to content

Commit

Permalink
[sql-hint addon] Properly quote quotes
Browse files Browse the repository at this point in the history
Identifiers that contain the identifierQuote like a table named
my"table are now doublicated correctly (e.g. quoting produces:
"my""table"). This fixes 2 failing tests, but 2 others still fail.
  • Loading branch information
crazy4chrissi authored and marijnh committed Mar 4, 2017
1 parent 595df8d commit 3c81665
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions addon/hint/sql-hint.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,21 @@
if (name.charAt(0) == ".") {
name = name.substr(1);
}
return name.replace(new RegExp(identifierQuote,"g"), "");
// replace doublicated identifierQuotes with single identifierQuotes
// and remove single identifierQuotes
var nameParts = name.split(identifierQuote+identifierQuote);
for (var i = 0; i < nameParts.length; i++)
nameParts[i] = nameParts[i].replace(new RegExp(identifierQuote,"g"), "");
return nameParts.join(identifierQuote);
}

function insertIdentifierQuotes(name) {
var nameParts = getText(name).split(".");
for (var i = 0; i < nameParts.length; i++)
nameParts[i] = identifierQuote + nameParts[i] + identifierQuote;
nameParts[i] = identifierQuote +
// doublicate identifierQuotes
nameParts[i].replace(new RegExp(identifierQuote,"g"), identifierQuote+identifierQuote) +
identifierQuote;
var escaped = nameParts.join(".");
if (typeof name == "string") return escaped;
name = shallowClone(name);
Expand Down

0 comments on commit 3c81665

Please sign in to comment.