From e1e9e03f0f1a58f253edea925b54d12fad294b9f Mon Sep 17 00:00:00 2001 From: jalisson Date: Fri, 10 Jul 2020 22:33:01 -0300 Subject: [PATCH] Null point comment --- .../utils/pgdiff/parsers/CommentParser.java | 2 +- .../cz/startnet/utils/pgdiff/parsers/Parser.java | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/java/cz/startnet/utils/pgdiff/parsers/CommentParser.java b/src/main/java/cz/startnet/utils/pgdiff/parsers/CommentParser.java index ac1cef99..27bf0a69 100755 --- a/src/main/java/cz/startnet/utils/pgdiff/parsers/CommentParser.java +++ b/src/main/java/cz/startnet/utils/pgdiff/parsers/CommentParser.java @@ -90,7 +90,7 @@ private static void parseConstraint(final Parser parser, final String tableName = parser.parseIdentifier(); final String objectName = ParserUtils.getObjectName(tableName); final String schemaName = - ParserUtils.getSchemaName(constraintName, database); + ParserUtils.getSchemaName(tableName, database); final PgConstraint constraint = database.getSchema(schemaName). getTable(objectName).getConstraint(constraintName); diff --git a/src/main/java/cz/startnet/utils/pgdiff/parsers/Parser.java b/src/main/java/cz/startnet/utils/pgdiff/parsers/Parser.java index 97743895..a2ffe132 100644 --- a/src/main/java/cz/startnet/utils/pgdiff/parsers/Parser.java +++ b/src/main/java/cz/startnet/utils/pgdiff/parsers/Parser.java @@ -102,7 +102,8 @@ public boolean expect(final String word, final boolean optional) { * @return true if whole sequence was found, otherwise false */ public boolean expectOptional(final String... words) { - final boolean found = expect(words[0], true); + final int oldPosition = position; + boolean found = expect(words[0], true); if (!found) { return false; @@ -110,7 +111,11 @@ public boolean expectOptional(final String... words) { for (int i = 1; i < words.length; i++) { skipWhitespace(); - expect(words[i]); + found = expect(words[i], true); + if (!found) { + position = oldPosition; + return false; + } } return true; @@ -249,7 +254,7 @@ public int parseInteger() { * * @return parsed string, if quoted then including quotes */ - public String parseString() { + public String parseString() { final boolean quoted = string.charAt(position) == '\''; if (quoted) { @@ -274,6 +279,11 @@ public String parseString() { final String result; try { + if (endPos >= string.length()) + { + //try to fix StringIndexOutOfBoundsException + endPos = string.lastIndexOf('\''); + } result = string.substring(position, endPos + 1); } catch (final Throwable ex) { throw new RuntimeException("Failed to get substring: " + string