fleet/frontend/utilities/node-sql-parser/sqlite.js

2 lines
194 KiB
JavaScript
Raw Normal View History

Allow ESCAPE in LIKE clauses to be valid SQL (#31222) for #30109 # Details This PR fixes an issue in our current SQL parsing library that was causing queries like this to be marked invalid: ``` SELECT * FROM table_name WHERE column_name LIKE '\_%' ESCAPE '\' ``` This is valid in SQLite because the `\` is not considered an escape character by default. From [the SQLite docs](https://www.sqlite.org/lang_expr.html) (see section 3 "Literal Values (Constants)"; emphasis mine): > A string constant is formed by enclosing the string in single quotes ('). A single quote within the string can be encoded by putting two single quotes in a row - as in Pascal. C-style escapes using the backslash character are not supported because they are not standard SQL. # Use of forked code Part of the fix for this was [submitted as a PR to the node-sql-parser library](https://github.com/taozhi8833998/node-sql-parser/pull/2496) we now use, and merged. I then found that another fix was needed, which I submitted as [a separate PR](https://github.com/taozhi8833998/node-sql-parser/pull/2512). As these fixes have yet to be made part of an official release of the library, I made a fork off of the release we were using (5.3.10) and bundled the necessary build artifacts with Fleet. We have an [ADR proposing the use of submodules for this purpose](https://github.com/fleetdm/fleet/pull/31079); I'm happy to implement that instead if we approve that, although for a front-end module with a build step it's a bit more complicated. Hopefully this code will be released in `node-sql-parser` soon and we can revert back to using the dependency. Here is the [full set of changes](https://github.com/taozhi8833998/node-sql-parser/compare/master...sgress454:node-sql-parser:5.3.10-plus). # Checklist for submitter - [X] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files) for more information. - [X] Manual QA for all new/changed functionality
2025-07-25 15:13:55 +00:00
!function(r,t){for(var e in t)r[e]=t[e]}(exports,function(r){var t={};function e(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return r[n].call(o.exports,o,o.exports,e),o.l=!0,o.exports}return e.m=r,e.c=t,e.d=function(r,t,n){e.o(r,t)||Object.defineProperty(r,t,{enumerable:!0,get:n})},e.r=function(r){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})},e.t=function(r,t){if(1&t&&(r=e(r)),8&t)return r;if(4&t&&"object"==typeof r&&r&&r.__esModule)return r;var n=Object.create(null);if(e.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:r}),2&t&&"string"!=typeof r)for(var o in r)e.d(n,o,function(t){return r[t]}.bind(null,o));return n},e.n=function(r){var t=r&&r.__esModule?function(){return r.default}:function(){return r};return e.d(t,"a",t),t},e.o=function(r,t){return Object.prototype.hasOwnProperty.call(r,t)},e.p="",e(e.s=1)}([function(r,t,e){"use strict";var n=e(2);function o(r,t,e,n){this.message=r,this.expected=t,this.found=e,this.location=n,this.name="SyntaxError","function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,o)}!function(r,t){function e(){this.constructor=r}e.prototype=t.prototype,r.prototype=new e}(o,Error),o.buildMessage=function(r,t){var e={literal:function(r){return'"'+o(r.text)+'"'},class:function(r){var t,e="";for(t=0;t<r.parts.length;t++)e+=r.parts[t]instanceof Array?u(r.parts[t][0])+"-"+u(r.parts[t][1]):u(r.parts[t]);return"["+(r.inverted?"^":"")+e+"]"},any:function(r){return"any character"},end:function(r){return"end of input"},other:function(r){return r.description}};function n(r){return r.charCodeAt(0).toString(16).toUpperCase()}function o(r){return r.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,(function(r){return"\\x0"+n(r)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(r){return"\\x"+n(r)}))}function u(r){return r.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,(function(r){return"\\x0"+n(r)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(r){return"\\x"+n(r)}))}return"Expected "+function(r){var t,n,o,u=new Array(r.length);for(t=0;t<r.length;t++)u[t]=(o=r[t],e[o.type](o));if(u.sort(),u.length>0){for(t=1,n=1;t<u.length;t++)u[t-1]!==u[t]&&(u[n]=u[t],n++);u.length=n}switch(u.length){case 1:return u[0];case 2:return u[0]+" or "+u[1];default:return u.slice(0,-1).join(", ")+", or "+u[u.length-1]}}(r)+" but "+function(r){return r?'"'+o(r)+'"':"end of input"}(t)+" found."},r.exports={SyntaxError:o,parse:function(r,t){t=void 0!==t?t:{};var e,u={},a={start:Cu},s=Cu,i=function(r,t){return gc(r,t,1)},c=yu("IF",!0),l=yu("if",!0),f=yu("exists",!0),p=yu("TRIGGER",!0),b=yu("BEFORE",!0),v=yu("AFTER",!0),y=yu("INSTEAD OF",!0),d=yu("ON",!0),h=yu("OF",!0),m=function(r,t){return gc(r,t)},w=yu("BEGIN",!0),L=yu("END",!0),C=yu("FOR",!0),A=yu("EACH",!0),E=yu("ROW",!0),g=yu("STATEMENT",!0),j=(yu("CASCADED",!0),yu("LOCAL",!0)),_=yu("CHECK",!0),T=(yu("OPTION",!1),function(r,t){return gc(r,t)}),S=yu("AUTO_INCREMENT",!0),x=yu("AUTOINCREMENT",!0),k=yu("UNIQUE",!0),I=yu("KEY",!0),N=yu("PRIMARY",!0),R=yu("COLUMN_FORMAT",!0),O=yu("FIXED",!0),U=yu("DYNAMIC",!0),M=yu("DEFAULT",!0),D=yu("STORAGE",!0),P=yu("DISK",!0),F=yu("MEMORY",!0),$=yu("first",!0),H=yu("after",!0),B=yu("FOREIGN",!0),q=yu("CHANGE",!0),G=yu("ALGORITHM",!0),W=yu("INSTANT",!0),Y=yu("INPLACE",!0),V=yu("COPY",!0),Q=yu("LOCK",!0),X=yu("NONE",!0),K=yu("SHARED",!0),z=yu("EXCLUSIVE",!0),Z=yu("NOT",!0),J=yu("REPLICATION",!0),rr=yu("FOREIGN KEY",!0),tr=yu("ENFORCED",!0),er=yu("MATCH FULL",!0),nr=yu("MATCH PARTIAL",!0),or=yu("MATCH SIMPLE",!0),ur=yu("RESTRICT",!0),ar=yu("CASCADE",!0),sr=yu("SET NULL",!0),ir=yu("NO ACTION",!0),cr=yu("SET DEFAULT",!0),lr=yu("CHARACTER",!0),fr=yu("SET",!0),pr=yu("CHARSET",!0),br=yu("COLLATE",!0),vr=yu("AVG_ROW_LENGTH",!0),yr=yu("KEY_BLOCK_SIZE",!0),dr=yu("MAX_RO
//# sourceMappingURL=sqlite.js.map