diff --git a/addon/hint/sql-hint.js b/addon/hint/sql-hint.js index d6b6774b29..a06e90a5e6 100644 --- a/addon/hint/sql-hint.js +++ b/addon/hint/sql-hint.js @@ -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); diff --git a/test/sql-hint-test.js b/test/sql-hint-test.js index 1094ec03de..712ca09e41 100644 --- a/test/sql-hint-test.js +++ b/test/sql-hint-test.js @@ -21,7 +21,13 @@ {text: "name", displayText: "name | The name"}] }]; - namespace = "sql-hint_"; + var problemTables = { + "backtick`table": ["backtick`col"], + "doublequote\"table": ["doublequote\"col"], + "space table": ["space column"] + }; + + namespace = "sql-hint_"; function test(name, spec) { testCM(name, function(cm) { @@ -220,6 +226,63 @@ to: Pos(0, 9) }) + test("backticktable", { + value: "SELECT `backtick", + cursor: Pos(0, 16), + tables: problemTables, + list: ["`backtick``table`"], + from: Pos(0, 7), + to: Pos(0, 16) + }); + + test("backticktable2", { + value: "SELECT `backtick``ta", + cursor: Pos(0, 20), + tables: problemTables, + list: ["`backtick``table`"], + from: Pos(0, 7), + to: Pos(0, 20) + }); + + test("backtickcolumn", { + value: "SELECT `backtick``table`.`back", + cursor: Pos(0, 29), + tables: problemTables, + list: ["`backtick``table`.`backtick``col`"], + from: Pos(0, 7), + to: Pos(0, 29) + }); + + test("doublequotetable", { + value: "SELECT \"doublequ", + cursor: Pos(0, 16), + tables: problemTables, + list: ["\"doublequote\"\"table\""], + from: Pos(0, 7), + to: Pos(0, 16), + mode: "text/x-sqlite" + }); + + test("doublequotecolumn", { + value: "SELECT \"doublequote\"\"table\".\"doubl", + cursor: Pos(0, 33), + tables: problemTables, + list: ["\"doublequote\"\"table\".\"doublequote\"\"col\""], + from: Pos(0, 7), + to: Pos(0, 33), + mode: "text/x-sqlite" + }); + + test("spacetable", { + value: "SELECT `space ta", + cursor: Pos(0, 16), + tables: problemTables, + list: ["`space table`"], + from: Pos(0, 7), + to: Pos(0, 16) + }); + + function deepCompare(a, b) { if (a === b) return true if (!(a && typeof a == "object") ||