Skip to content

Commit

Permalink
Merge pull request #40610 from SasinduDilshara/issue_40541
Browse files Browse the repository at this point in the history
Fix NPE in regex parser with single quantifiers
  • Loading branch information
pcnfernando authored Jul 10, 2023
2 parents 51103a0 + 3515654 commit 5ba631c
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -507,8 +507,8 @@ private STNode parseBaseQuantifier() {
openBrace = invalidateNonDigitNodesAndAddToTrailingMinutiae(openBrace, true);
}
STNode leastDigits = parseDigits(true);
STNode comma = null;
STNode mostDigits = null;
STNode comma = STNodeFactory.createEmptyNode();;
STNode mostDigits = STNodeFactory.createEmptyNodeList();
nextToken = peek();
if (nextToken.kind == SyntaxKind.COMMA_TOKEN) {
comma = consume();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,10 @@
}
]
},
{
"kind": "LIST",
"children": []
},
{
"kind": "CLOSE_BRACE_TOKEN"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,10 @@
}
]
},
{
"kind": "LIST",
"children": []
},
{
"kind": "CLOSE_BRACE_TOKEN"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,10 @@
}
]
},
{
"kind": "LIST",
"children": []
},
{
"kind": "CLOSE_BRACE_TOKEN"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@
}
]
},
{
"kind": "LIST",
"children": []
},
{
"kind": "CLOSE_BRACE_TOKEN"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@
}
]
},
{
"kind": "LIST",
"children": []
},
{
"kind": "CLOSE_BRACE_TOKEN"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
type AnnotRec record {|
string:RegExp value;
|};

annotation AnnotRec annot on type;

@annot {
value: re `abc{1}`
}
type Foo record {
string name;
};

@annot {
value: re `abc{1,}`
}
type Foo2 record {
string name;
};

@annot {
value: re `abc{1,2}`
}
type Foo3 record {
string name;
};

public function test1() {
Foo _ = {name: "abc"};
Foo2 _ = {name: "abc"};
Foo3 _ = {name: "abc"};
}

public function test2() {
string:RegExp _ = re `[A-Z]{1}`;
string:RegExp _ = re `[A-Z]{1,2}`;
string:RegExp _ = re `[A-Z]{1,}`;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
type AnnotRec record {|
string:RegExp value;
|};

annotation AnnotRec annot on type;

@annot {
value: re `abc{1}`
}
type Foo record {
string name;
};

@annot {
value: re `abc{1,}`
}
type Foo2 record {
string name;
};

@annot {
value: re `abc{1,2}`
}
type Foo3 record {
string name;
};

public function test1() {
Foo _={name: "abc"};
Foo2 _={name: "abc"};
Foo3 _={name: "abc"};
}

public function test2() {
string:RegExp _=re `[A-Z]{1}`;
string:RegExp _=re `[A-Z]{1,2}`;
string:RegExp _=re `[A-Z]{1,}`;
}

0 comments on commit 5ba631c

Please sign in to comment.