Bug #9969
Parsing query string error with \r character.
100%
Related issues
History
#1 Updated by Eduard Soltan about 1 year ago
def var h as handle.
def temp-table tt1 field f1 as int
field f2 as char.
def var fooClass as oo.FooTest.
create tt1.
tt1.f1 = 4.
release tt1.
def query hquery for tt1.
do transaction on error undo, throw:
def var ch1 as char.
ch1 = "FOR EACH tt1 WHERE tt1.f1 < 9 and tt1.f2 = 'bc".
message length(ch1).
ch1 = ch1 + chr(13).
ch1 = ch1 + "'".
query hQuery:QUERY-PREPARE(ch1).
message ch1.
end.
The following code will execute without any exception in 4gl, however in FWD it will raised the following error ** Unmatched quote found in procedure. (133).
#2 Updated by Eduard Soltan about 1 year ago
- Related to Bug #4602: fixes for OO 4GL and structured error handling added
#3 Updated by Eduard Soltan about 1 year ago
Alternatively this test case also reproduce the issues:
def var h as handle.
def temp-table tt1 field f1 as int
field f2 as char.
def var fooClass as oo.FooTest.
create tt1.
tt1.f1 = 4.
release tt1.
def query hquery for tt1.
do transaction on error undo, throw:
def var ch1 as char.
ch1 = "FOR EACH tt1 WHERE tt1.f1 < 9 and tt1.f2 = 'bc\r'".
message length(ch1).
query hQuery:QUERY-PREPARE(ch1).
message ch1.
end.
#4 Updated by Greg Shah about 1 year ago
Our preprocessor/lexer strips '\r' characters in a naive way that needs to be refined.
#5 Updated by Greg Shah about 1 year ago
- Assignee set to Octavian Adrian Gavril
#6 Updated by Alexandru Lungu about 1 year ago
Eduard, is 'bc\r' right? Shouldn't it be 'bc~r' to actually generate the CR?
#7 Updated by Constantin Asofiei about 1 year ago
Please also see #9967, which is somehow related to the escape char used under linux.
#8 Updated by Eduard Soltan about 1 year ago
Alexandru Lungu wrote:
Eduard, is
'bc\r'right? Shouldn't it be'bc~r'to actually generate the CR?
It is either of them. In both cases in fwd a exception is thrown. The original case in customer application was with ch = ch + char(13).
#9 Updated by Octavian Adrian Gavril about 1 year ago
The escape sequences should include an additional '\' prefix. The current revision handles this only for '\u' within comments. The '\r' character is processed only in specific contexts. I'm currently investigating this.
#10 Updated by Octavian Adrian Gavril about 1 year ago
- Status changed from New to WIP
#11 Updated by Octavian Adrian Gavril about 1 year ago
- % Done changed from 0 to 70
Greg wrote:
Octavian Adrian Gavril wrote:
I investigated the issue. I think we can apply the "\r" processing done in ClearStream to the content of dynamic queries as well. This way, there will be no characters that are not suitable for the parser.
I'm worried about this idea. If the 4GL code can actually do something with \r then "eating them" in ClearStream is not the right thing to do. Post in the task and we will discuss it there.
I abandoned this idea because there are differences in string length and equality. I've these changes in task branch 9969a/15895:
@@ -39001,13 +39003,27 @@
}
| '\n' { newline(); } // otherwise allow NL
- | ~'\'' // anything else except closing '
+ | NON_QUOTE_CHAR // anything else except closing '
)*
'\'' // closing '
)
;
/**
+ * Matches any single character except a single quote (`'`).
+ */
+NON_QUOTE_CHAR
+ : ~'\''
+ ;
+
+/**
+ * Matches any single character except a single quote (`"`).
+ */
+NON_DOUBLE_QUOTE_CHAR
+ : ~'\"'
+ ;
+
+/**
* Matches an opening double quote, arbitrary contents and an ending double
* quote. Two contiguous double quote characters and an escape prefixed
* double quote character are accepted as contents (they do not terminate
@@ -39108,7 +39124,7 @@
}
| '\n' { newline(); } // otherwise allow NL
- | ~'\"' // anything else except closing "
+ | NON_DOUBLE_QUOTE_CHAR // anything else except closing "
)*
'\"' // closing "
)
It seems that the token set generated for ~... does not contain \r because this character is processed further down in another branch of the rule. Even if that match is conditional on { schema }?, the character is still excluded. Since these sets are generated before generating the target parser/lexer code, they cannot be modified. Separating the branches into different rules will force ANTLR to accept \r in ~'\''. I did the same for the double quote scenario. I tested with this testcase and the runtime works fine:
def var h as handle.
def temp-table tt1 field f1 as int
field f2 as char.
create tt1.
tt1.f1 = 4.
release tt1.
def query hquery for tt1.
do transaction on error undo, throw:
def var ch1 as char.
ch1 = 'FOR EACH tt1 WHERE tt1.f1 < 9 and tt1.f2 = "bc~r"'.
message length(ch1).
query hQuery:QUERY-PREPARE(ch1).
message ch1.
ch1 = "FOR EACH tt1 WHERE tt1.f1 < 9 and tt1.f2 = 'bc~r'".
query hQuery:QUERY-PREPARE(ch1).
message ch1.
end. #12 Updated by Octavian Adrian Gavril about 1 year ago
Branch 9969a was rebased with trunk. The new revision is 15901.
#13 Updated by Octavian Adrian Gavril about 1 year ago
I made a few changes that fix the way Java escaping is handled. First, in ClearStream.java sequences (with '\') are translated exactly when unixEscapes is true. Then, in character.progressToJavaString everything escaped with "/" is double escaped to avoid honoring Java escaping. These changes are made in 9969a/15902. With these changes, #9967 is also fixed.
#14 Updated by Octavian Adrian Gavril about 1 year ago
- Status changed from WIP to Review
- % Done changed from 70 to 100
- reviewer Constantin Asofiei, Ovidiu Maxiniuc added
#15 Updated by Ovidiu Maxiniuc about 1 year ago
Review of 9969a/r15902.
UnicodeTranslationException: missing javadocs for both the class and the constructor (I am aware this was committed in 15900, for #8027). Please take this opportunity and add them now;progress.g: My understanding is that the inlines for non'and non"were replaced with the new rules (NON_QUOTE_CHAR, andNON_DOUBLE_QUOTE_CHAR), so I expect the result will not change. Will these fix the issue in note #9969-11?ClearStreamandcharacter: I think that is exactly what the H entries describe.
#16 Updated by Octavian Adrian Gavril about 1 year ago
Ovidiu Maxiniuc wrote:
Review of 9969a/r15902.
progress.g: My understanding is that the inlines for non'and non"were replaced with the new rules (NON_QUOTE_CHAR, andNON_DOUBLE_QUOTE_CHAR), so I expect the result will not change. Will these fix the issue in note #9969-11?
Yes because without changes, ANTLR generates a token set to match non quote characters. That token set doesn't contain '\r':
else if ((_tokenSet_7.member(LA(1)))) {
matchNot('\'');
}
Separating that case will not exclude '\r':
public final void mNON_DOUBLE_QUOTE_CHAR(boolean _createToken) throws RecognitionException, CharStreamException, TokenStreamException {
int _ttype; Token _token=null; int _begin=text.length();
_ttype = NON_DOUBLE_QUOTE_CHAR;
int _saveIndex;
matchNot('\"');
if ( _createToken && _token==null && _ttype!=Token.SKIP ) {
_token = makeToken(_ttype);
_token.setText(new String(text.getBuffer(), _begin, text.length()-_begin));
}
_returnToken = _token;
}#17 Updated by Octavian Adrian Gavril about 1 year ago
Ovidiu Maxiniuc wrote:
Review of 9969a/r15902.
UnicodeTranslationException: missing javadocs for both the class and the constructor (I am aware this was committed in 15900, for #8027). Please take this opportunity and add them now;
Fixed in 9969a/15903.
#18 Updated by Greg Shah about 1 year ago
- Status changed from Review to Internal Test
Code Review Task Branch 9969a Revisions 15901 through 15903
I'm OK with the changes. Let's get it tested across a wide range of applications.
#19 Updated by Octavian Adrian Gavril about 1 year ago
Is conversion regression tesing necessary or run-time testing is enough?
#20 Updated by Greg Shah about 1 year ago
This affects all string processing in the lexer in a profound way. Full conversion testing is needed.
#21 Updated by Octavian Adrian Gavril about 1 year ago
The conversion of a large GUI client application has been completed successfully. The conversion log is clean and there are no unexpected changes. All unit tests passed. ✅
I will get the results for another GUI application and an application server application soon. In the meantime, I am converting the ChUI regression testing application.
#22 Updated by Octavian Adrian Gavril about 1 year ago
The conversion of the ChUI regression test application completed successfully, but the source compilation failed. The cause is the changes in the secondary part of the problem, those in character.java. The problematic scenario is ch = "\\". The code converted with 15903 looks like this: ch.assign("\\\"). I need to get rid of all backslashes if windows is enabled.
#23 Updated by Octavian Adrian Gavril about 1 year ago
- % Done changed from 100 to 90
- Status changed from Internal Test to WIP
#24 Updated by Octavian Adrian Gavril about 1 year ago
- Status changed from WIP to Review
- % Done changed from 90 to 100
I've reverted the changes from character.java in 9969a/15904. This double backslash gets an unescaped '\' character in a Java source string, whether unixEscapes is set to false or true. When unixEscapes is true the string is processed here in character.progressToJavaString:
case '~':
case '\\':
// on Windows we have to make special processing for '\' characters since they are
// not escape chars
if (windows && current == '\\')
{
// backslash must be doubled to get one unescaped \ char in a Java source string
sb.append("\\\\");
I used this testcase to see if the behavior is as expected:
message "~225 \225 ~U0020AC \U0020AC ~u2022 \u2022 ~u202 ~u2222 ~r \r ~t \t \\ ~\" VIEW-AS ALERT-BOX.
Converted code with unixEscapes on true:
messageBox("• • € € • • ~u202 ~u2222 \r \r \t \t \\ \\", ALERT_MESSAGE, BTN_OK, (String) null);
Converted code with unixEscapes on false:
messageBox("• \\225 € \\U0020AC • \\u2022 ~u202 ~u2222 \r \\r \t \\t \\\\ \\", ALERT_MESSAGE, BTN_OK, (String) null);#25 Updated by Octavian Adrian Gavril about 1 year ago
- Status changed from Review to Internal Test
- Conversion of large GUI customer application completed successfully. Conversion log is clean and there are no unexpected changes. All unit tests passed. ✅
- Conversion of ChUI regression testing application completed successfully. Conversion log is clean and there are no source code differences. ✅
I will get the results for another GUI application and an application server application soon.
#26 Updated by Octavian Adrian Gavril about 1 year ago
The conversion of another large GUI customer application was successfully completed. No source code differences were detected, the runtime behaves as expected, and the logs show no anomalies. ✅
#27 Updated by Octavian Adrian Gavril about 1 year ago
Eduard mentioned in #4602-50 that exception is not thrown anymore.
#28 Updated by Greg Shah about 1 year ago
I used this testcase to see if the behavior is as expected:
[...]Converted code with
unixEscapesontrue:
[...]Converted code with
unixEscapesonfalse:
[...]
What is the output for OE?
#29 Updated by Octavian Adrian Gavril about 1 year ago
Greg Shah wrote:
I used this testcase to see if the behavior is as expected:
[...]Converted code with
unixEscapesontrue:
[...]Converted code with
unixEscapesonfalse:
[...]What is the output for OE?
This one:
--------------------------- Message (Press HELP to view stack trace) --------------------------- • \225 € \U0020AC • \u2022 ~u202 ~u2222 \r \t \\ \ --------------------------- OK Help ---------------------------
The malformed Unicode sequence and the backslash escapes are not translated.
#30 Updated by Greg Shah about 1 year ago
- Status changed from Internal Test to Merge Pending
You can merge to trunk now.
#31 Updated by Octavian Adrian Gavril about 1 year ago
Shouldn't I wait for the appserver application conversion test results?
#32 Updated by Greg Shah about 1 year ago
- Status changed from Merge Pending to Internal Test
Yes, you're right.
#33 Updated by Octavian Adrian Gavril about 1 year ago
Conversion of appserver application completed successfully. The runtime is also working fine.
#34 Updated by Greg Shah about 1 year ago
- Status changed from Internal Test to Merge Pending
Please merge to trunk after 9834a.
#35 Updated by Octavian Adrian Gavril about 1 year ago
- Status changed from Merge Pending to Test
- version_resolved set to 15910
Branch 9969a was merged into trunk as rev. 15910 and archived.
#36 Updated by Constantin Asofiei about 1 year ago
Octavian, I think there may be a problem. In a project there is a var defined like:
define variable ch as character initial "~000doesntmatterelse":U no-undo.
Note the null character first (escaped) this is emitted 'as is' (unescaped) in the Java code, making it 1. uneditable using gedit or something like this, and 2. in eclipse, the line with the var will 'drop' everything after the null char.
We need to escape the null char.
#37 Updated by Octavian Adrian Gavril about 1 year ago
Constantin Asofiei wrote:
Octavian, I think there may be a problem. In a project there is a var defined like:
[...]Note the null character first (escaped) this is emitted 'as is' (unescaped) in the Java code, making it 1. uneditable using gedit or something like this, and 2. in eclipse, the line with the var will 'drop' everything after the null char.
We need to escape the null char.
I think this is an exception that could be handled in the same way as control characters:
else if (result == 126)
{
super.unread('~');
clearCount++;
}
else if (!notInStrings)
{
switch(result)
{
case '\b':
super.unread('b');
clearCount++;
return '~';
case '\t':
super.unread('t');
clearCount++;
return '~';
case '\n':
super.unread('n');
clearCount++;
return '~';
case '\f':
super.unread('f');
clearCount++;
return '~';
case '\r':
super.unread('r');
clearCount++;
return '~';
case '\\':
super.unread('\\');
clearCount++;
return '~';
}#38 Updated by Octavian Adrian Gavril about 1 year ago
This is more related to #8027 than this task.
#39 Updated by Constantin Asofiei about 1 year ago
I think we need to handle and escape all control characters - see https://www.ascii-code.com/characters/control-characters
I don't know from which task the problem arises in the customer project (this was the last commit I saw somehow related) - please work on #8027 if is from there. We need this fixed, as it is now the code doesn't convert properly. I haven't checked the .class bytecode if is right or not.
#40 Updated by Octavian Adrian Gavril about 1 year ago
Constantin Asofiei wrote:
I think we need to handle and escape all control characters - see https://www.ascii-code.com/characters/control-characters
I don't know from which task the problem arises in the customer project (this was the last commit I saw somehow related) - please work on #8027 if is from there. We need this fixed, as it is now the code doesn't convert properly. I haven't checked the .class bytecode if is right or not.
Sure! I'll take care of it.
#41 Updated by Ovidiu Maxiniuc about 1 year ago
After upgrading to trunk 15913 (including 15910), the antlr build target results in a lot (30+) of nondeterminism errors, like this:
progress.g: warning:lexical nondeterminism between rules WS and NON_QUOTE_CHAR upon progress.g: k==1:'\u0000'..' ','\u007f' progress.g: k==2:<end-of-token> progress.g: k==3:<end-of-token> progress.g: k==4:<end-of-token>I know the full parser will be rewritten in a future but having all these, even benignant, may hide (make difficult to spot) eventual errors in the future.
#42 Updated by Octavian Adrian Gavril about 1 year ago
Ovidiu Maxiniuc wrote:
After upgrading to trunk 15913 (including 15910), the antlr build target results in a lot (30+) of nondeterminism errors, like this:
[...]I know the full parser will be rewritten in a future but having all these, even benignant, may hide (make difficult to spot) eventual errors in the future.
I tested and this is fixed if protected access modifier is added to NON_QUOTE_CHAR and NON_DOUBLE_QUOTE_CHAR rules. I will include this changes in the fix for #9969-36.
#43 Updated by Octavian Adrian Gavril about 1 year ago
- Status changed from Test to WIP
Reverted rev 15910 and rev 15900 from trunk in 15920.
#44 Updated by Octavian Adrian Gavril about 1 year ago
- Related to Bug #10028: FWD needs full support for unicode/octal escape sequences added
#45 Updated by Greg Shah about 1 year ago
- Related to Support #6859: preprocessor tests added