Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error parsing C-style strings #2

Closed
benjie opened this issue May 1, 2019 · 4 comments
Closed

Error parsing C-style strings #2

benjie opened this issue May 1, 2019 · 4 comments
Labels

Comments

@benjie
Copy link

benjie commented May 1, 2019

PostgreSQL supports C-style string escaping in E'' strings:

https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS-ESCAPE

e.g.:

# select E'\'' as example;
 example
---------
 '
(1 row)

Time: 0.241 ms

However pg-minify v1.0.0 (and v0.5.5) baulks at this:

> m = require('pg-minify')
[Function: minify] {
  SQLParsingError: [Function: SQLParsingError],
  parsingErrorCode: {
    unclosedMLC: 0,
    unclosedText: 1,
    unclosedQI: 2,
    multiLineQI: 3,
    nestedMLC: 4
  }
}
> m("select E'\'' as example;")
Thrown:
SQLParsingError: 1
    at new SQLParsingError (/Users/benjiegillam/Dev/graphile-migrate/node_modules/pg-minify/lib/error.js:25:24)
    at throwError (/Users/benjiegillam/Dev/graphile-migrate/node_modules/pg-minify/lib/parser.js:177:15)
    at minify (/Users/benjiegillam/Dev/graphile-migrate/node_modules/pg-minify/lib/parser.js:113:17)
    at repl:1:1
    at Script.runInThisContext (vm.js:123:20)
    at REPLServer.defaultEval (repl.js:358:29)
    at bound (domain.js:415:14)
    at REPLServer.runBound [as eval] (domain.js:428:12)
    at REPLServer.onLine (repl.js:665:10)
    at REPLServer.emit (events.js:201:15) {
  name: 'SQLParsingError',
  stack: 'SQLParsingError: 1\n    at new SQLParsingError ' +
    '(/Users/benjiegillam/Dev/graphile-migrate/node_modules/pg-minify/lib/error.js:25:24)\n' +
    '    at throwError ' +
    '(/Users/benjiegillam/Dev/graphile-migrate/node_modules/pg-minify/lib/parser.js:177:15)\n' +
    '    at minify ' +
    '(/Users/benjiegillam/Dev/graphile-migrate/node_modules/pg-minify/lib/parser.js:113:17)\n' +
    '    at repl:1:1\n    at Script.runInThisContext (vm.js:123:20)\n    at ' +
    'REPLServer.defaultEval (repl.js:358:29)\n    at bound ' +
    '(domain.js:415:14)\n    at REPLServer.runBound [as eval] ' +
    '(domain.js:428:12)\n    at REPLServer.onLine (repl.js:665:10)\n    at ' +
    'REPLServer.emit (events.js:201:15)',
  code: 1,
  error: 'Unclosed text block.',
  position: { line: 1, column: 9 },
  message: 'Error parsing SQL at {line:1,col:9}: Unclosed text block.'
}
>
@vitaly-t vitaly-t added the bug label May 8, 2019
@vitaly-t
Copy link
Owner

vitaly-t commented May 8, 2019

Yes, this seems like a special case that's not supported at the moment.

The library expects that \' is escaped as '', which then works.

It will require some tweaking to make the reported case work also.

@vitaly-t
Copy link
Owner

vitaly-t commented May 8, 2019

I'm trying to come up with a RegEx that would help me skip those special cases, without complicating the algorithm further. I had to open a question on StackOverflow for it, as I got stuck with such a RegEx.

We just need to skip every ' that's preceded by an odd number of \.

vitaly-t added a commit that referenced this issue May 8, 2019
@vitaly-t
Copy link
Owner

vitaly-t commented May 8, 2019

Fixed in v1.1.0, and in much a simpler way, without any RegEx.

@benjie Thanks for reporting!

@vitaly-t vitaly-t closed this as completed May 8, 2019
@vitaly-t
Copy link
Owner

@benjie Release 1.2.0 now makes this library way better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants