From: Dagfinn Ilmari Mannsåker Date: Mon, 7 Sep 2015 16:49:27 +0000 (+0100) Subject: Fix parsing quoted strings with leading spaces X-Git-Tag: v0.11022~26 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=fd498bb0acde8fb312f841aaebc896ed19db59d1;p=dbsrgits%2FSQL-Translator.git Fix parsing quoted strings with leading spaces --- diff --git a/Changes b/Changes index 4198719..d7b98a5 100644 --- a/Changes +++ b/Changes @@ -11,6 +11,8 @@ Changes for SQL::Translator * Declare dependencies in deterministic order (RT#102859) * Multiple speedups of naive internal debugging mechanism (GH#54) * Remove dependency on List::MoreUtils ( http://is.gd/lmu_cac_debacle ) + * Fix parsing of strings with leading whitespace for MySQL, Oracle, PostgreSQL, + SQLServer and SQLite 0.11021 2015-01-29 diff --git a/lib/SQL/Translator/Parser/MySQL.pm b/lib/SQL/Translator/Parser/MySQL.pm index 4b1fcec..8cdd794 100644 --- a/lib/SQL/Translator/Parser/MySQL.pm +++ b/lib/SQL/Translator/Parser/MySQL.pm @@ -853,14 +853,14 @@ QUOTED_NAME : BQSTRING # MySQL strings, unlike common SQL strings, can have the delmiters # escaped either by doubling or by backslashing. -BQSTRING: BACKTICK /(?:[^\\`]|``|\\.)*/ BACKTICK - { ($return = $item[2]) =~ s/(\\[\\`]|``)/substr($1,1)/ge } +BQSTRING: BACKTICK /(?:[^\\`]|``|\\.)*/ BACKTICK + { ($return = $item[3]) =~ s/(\\[\\`]|``)/substr($1,1)/ge } -DQSTRING: DOUBLE_QUOTE /(?:[^\\"]|""|\\.)*/ DOUBLE_QUOTE - { ($return = $item[2]) =~ s/(\\[\\"]|"")/substr($1,1)/ge } +DQSTRING: DOUBLE_QUOTE /(?:[^\\"]|""|\\.)*/ DOUBLE_QUOTE + { ($return = $item[3]) =~ s/(\\[\\"]|"")/substr($1,1)/ge } -SQSTRING: SINGLE_QUOTE /(?:[^\\']|''|\\.)*/ SINGLE_QUOTE - { ($return = $item[2]) =~ s/(\\[\\']|'')/substr($1,1)/ge } +SQSTRING: SINGLE_QUOTE /(?:[^\\']|''|\\.)*/ SINGLE_QUOTE + { ($return = $item[3]) =~ s/(\\[\\']|'')/substr($1,1)/ge } NAME: QUOTED_NAME diff --git a/lib/SQL/Translator/Parser/Oracle.pm b/lib/SQL/Translator/Parser/Oracle.pm index 7a3bb23..12e7fdf 100644 --- a/lib/SQL/Translator/Parser/Oracle.pm +++ b/lib/SQL/Translator/Parser/Oracle.pm @@ -605,11 +605,11 @@ NAME : /\w+/ { $item[1] } TABLE : /table/i -DQSTRING : '"' /((?:[^"]|"")+)/ '"' - { ($return = $item[2]) =~ s/""/"/g; } +DQSTRING : '"' /((?:[^"]|"")+)/ '"' + { ($return = $item[3]) =~ s/""/"/g; } -SQSTRING : "'" /((?:[^']|'')*)/ "'" - { ($return = $item[2]) =~ s/''/'/g } +SQSTRING : "'" /((?:[^']|'')*)/ "'" + { ($return = $item[3]) =~ s/''/'/g } VALUE : /[-+]?\d*\.?\d+(?:[eE]\d+)?/ | SQSTRING diff --git a/lib/SQL/Translator/Parser/PostgreSQL.pm b/lib/SQL/Translator/Parser/PostgreSQL.pm index 504d365..ad4ec64 100644 --- a/lib/SQL/Translator/Parser/PostgreSQL.pm +++ b/lib/SQL/Translator/Parser/PostgreSQL.pm @@ -1006,11 +1006,11 @@ SET : /set/i NAME : DQSTRING | /\w+/ -DQSTRING : '"' /((?:[^"]|"")+)/ '"' - { ($return = $item[2]) =~ s/""/"/g; } +DQSTRING : '"' /((?:[^"]|"")+)/ '"' + { ($return = $item[3]) =~ s/""/"/g; } -SQSTRING : "'" /((?:[^']|'')*)/ "'" - { ($return = $item[2]) =~ s/''/'/g } +SQSTRING : "'" /((?:[^']|'')*)/ "'" + { ($return = $item[3]) =~ s/''/'/g } VALUE : /[-+]?\d*\.?\d+(?:[eE]\d+)?/ | SQSTRING diff --git a/lib/SQL/Translator/Parser/SQLServer.pm b/lib/SQL/Translator/Parser/SQLServer.pm index 3834de1..c4191fd 100644 --- a/lib/SQL/Translator/Parser/SQLServer.pm +++ b/lib/SQL/Translator/Parser/SQLServer.pm @@ -440,14 +440,14 @@ DIGITS : /\d+/ COMMA : ',' -SQSTRING : "'" /(?:[^']|'')*/ "'" - { ($return = $item[2]) =~ s/''/'/g } +SQSTRING : "'" /(?:[^']|'')*/ "'" + { ($return = $item[3]) =~ s/''/'/g } -DQSTRING : '"' /(?:[^"]|"")+/ '"' - { ($return = $item[2]) =~ s/""/"/g } +DQSTRING : '"' /(?:[^"]|"")+/ '"' + { ($return = $item[3]) =~ s/""/"/g } -BQSTRING : '[' /(?:[^]]|]])+/ ']' - { ($return = $item[2]) =~ s/]]/]/g; } +BQSTRING : '[' /(?:[^]]|]])+/ ']' + { ($return = $item[3]) =~ s/]]/]/g; } END_OF_GRAMMAR diff --git a/lib/SQL/Translator/Parser/SQLite.pm b/lib/SQL/Translator/Parser/SQLite.pm index b3e81ae..4787302 100644 --- a/lib/SQL/Translator/Parser/SQLite.pm +++ b/lib/SQL/Translator/Parser/SQLite.pm @@ -623,11 +623,11 @@ NAME : /\w+/ | DQSTRING | SQSTRING -DQSTRING : '"' /((?:[^"]|"")+)/ '"' - { ($return = $item[2]) =~ s/""/"/g } +DQSTRING : '"' /((?:[^"]|"")+)/ '"' + { ($return = $item[3]) =~ s/""/"/g } -SQSTRING : "'" /((?:[^']|'')*)/ "'" - { ($return = $item[2]) =~ s/''/'/g } +SQSTRING : "'" /((?:[^']|'')*)/ "'" + { ($return = $item[3]) =~ s/''/'/g } VALUE : /[-+]?\d*\.?\d+(?:[eE]\d+)?/ { $item[1] } diff --git a/t/data/roundtrip.xml b/t/data/roundtrip.xml index 28d39ff..98fff7e 100644 --- a/t/data/roundtrip.xml +++ b/t/data/roundtrip.xml @@ -99,6 +99,16 @@ Created on Fri Aug 15 15:08:18 2003 + + + + + + +