Skip to content

Commit bef62e9

Browse files
committed
Fix hexidecimal strings
1 parent b3abeed commit bef62e9

File tree

1 file changed

+14
-55
lines changed

1 file changed

+14
-55
lines changed

src/backend/parser/ag_scanner.l

+14-55
Original file line numberDiff line numberDiff line change
@@ -798,31 +798,13 @@ ag_token token;
798798
BEGIN(xb);
799799
//strbuf_append_char(&yyextra.literal_buf, 'b');
800800
}
801-
<xb>{xbinside} {
802-
strbuf_append_buf(&yyextra.literal_buf, yytext, yyleng);
803-
}
801+
804802
<xb><<EOF>> {
805803
ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR),
806804
scan_errmsg("unterminated hexadecimal string literal"),
807805
scan_errposition()));
808806
}
809807

810-
<xb>{squote} {
811-
BEGIN(INITIAL);
812-
813-
/*
814-
* In quoted strings, only Unicode escape sequences need to be verified,
815-
* and the actions for <dqstr,sqstr>{esunicode} and <qstru>{esunicode}
816-
* rules verify the code point values. So, quoted strings are always valid.
817-
*/
818-
819-
token.type = AG_TOKEN_BCONST;
820-
token.value.s = strbuf_get_str(&yyextra.literal_buf);
821-
token.location = get_location();
822-
return token;
823-
}
824-
825-
826808
{xhstart} {
827809
/* Hexadecimal bit type.
828810
* At some point we should simply pass the string
@@ -833,35 +815,18 @@ ag_token token;
833815
BEGIN(xh);
834816
strbuf_append_char(&yyextra.literal_buf, 'x');
835817
}
836-
837-
<xh>{xhinside} {
818+
819+
<xh>{xhinside} |
820+
<xb>{xbinside} {
838821
strbuf_append_buf(&yyextra.literal_buf, yytext, yyleng);
839822
}
823+
840824
<xh><<EOF>> {
841825
ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR),
842826
scan_errmsg("unterminated hexadecimal string literal"),
843827
scan_errposition()));
844828
}
845829

846-
<xh>{squote} {
847-
BEGIN(INITIAL);
848-
849-
/*
850-
* In quoted strings, only Unicode escape sequences need to be verified,
851-
* and the actions for <dqstr,sqstr>{esunicode} and <qstru>{esunicode}
852-
* rules verify the code point values. So, quoted strings are always valid.
853-
*/
854-
855-
token.type = AG_TOKEN_XCONST;
856-
//token.value.s = strbuf_get_str(&yyextra.literal_buf);
857-
//token.value.s = copy_string(strbuf_get_str(&yyextra.literal_buf), yyleng);
858-
token.value.s = strbuf_get_str(&yyextra.literal_buf);
859-
token.location = get_location();
860-
return token;
861-
}
862-
863-
864-
865830
{xestart} {
866831
yyextra.warn_on_first_escape = false;
867832
yyextra.saw_non_ascii = false;
@@ -877,8 +842,7 @@ ag_token token;
877842
*/
878843
BEGIN(yyextra.state_before_str_stop);
879844
}
880-
<xqs>{quotecontinuefail} |
881-
<xqs>{other} |
845+
882846
<xb,xh,xq,xe,xus>{squote} {
883847
/*
884848
* When we are scanning a quoted string and see an end
@@ -906,18 +870,17 @@ ag_token token;
906870
switch (yyextra.state_before_str_stop)
907871
{
908872
case xb:
909-
910873
token.type = AG_TOKEN_BCONST;
911874
token.value.s = strbuf_get_str(&yyextra.literal_buf);
912875
token.location = get_location();
876+
strbuf_reset(&yyextra.literal_buf);
913877
return token;
914878
case xh:
915879
token.type = AG_TOKEN_XCONST;
916880
token.value.s = strbuf_get_str(&yyextra.literal_buf);
917881
token.location = get_location();
882+
strbuf_reset(&yyextra.literal_buf);
918883
return token;
919-
//yylval->str = litbufdup(yyscanner);
920-
//return XCONST;
921884
case xq:
922885
case xe:
923886
/*
@@ -928,27 +891,23 @@ ag_token token;
928891
pg_verifymbstr(yyextra.literal_buf.buffer,
929892
yyextra.literal_buf.length,
930893
false);
931-
//yylval->str = litbufdup(yyscanner);
932-
//return SCONST;
894+
933895
token.type = AG_TOKEN_STRING;
934896
token.value.s = strbuf_get_str(&yyextra.literal_buf);
935897
token.location = get_location();
898+
strbuf_reset(&yyextra.literal_buf);
936899
return token;
937900
case xus:
938901
token.type = AG_TOKEN_STRING;
939902
token.value.s = strbuf_get_str(&yyextra.literal_buf);
940903
token.location = get_location();
904+
strbuf_reset(&yyextra.literal_buf);
941905
return token;
942-
//yylval->str = litbufdup(yyscanner);
943-
//return USCONST;
906+
944907
default:{
945-
token.type = AG_TOKEN_STRING;
946-
token.value.s = strbuf_get_str(&yyextra.literal_buf);
947-
token.location = get_location();
948-
return token;
949-
/*ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR),
908+
ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR),
950909
scan_errmsg("unhandled previous state in xqs"),
951-
scan_errposition()));*/
910+
scan_errposition()));
952911
}
953912
}
954913
}

0 commit comments

Comments
 (0)