Skip to content

Commit e9e9840

Browse files
authored
Merge pull request #3301 from github/koesie10/improve-ruby-access-path-parsing
Fix Ruby method parsing for methods containing brackets
2 parents 74c101b + 8c72fe0 commit e9e9840

1 file changed

Lines changed: 26 additions & 3 deletions

File tree

extensions/ql-vscode/src/model-editor/languages/ruby/access-paths.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1+
import { parseAccessPathTokens } from "../../shared/access-paths";
2+
3+
const methodTokenRegex = /^Method\[(.+)]$/;
4+
15
export function parseRubyMethodFromPath(path: string): string {
2-
const match = path.match(/Method\[([^\]]+)].*/);
6+
const tokens = parseAccessPathTokens(path);
7+
8+
if (tokens.length === 0) {
9+
return "";
10+
}
11+
12+
const match = tokens[0].text.match(methodTokenRegex);
313
if (match) {
414
return match[1];
515
} else {
@@ -11,9 +21,22 @@ export function parseRubyAccessPath(path: string): {
1121
methodName: string;
1222
path: string;
1323
} {
14-
const match = path.match(/Method\[([^\]]+)]\.(.*)/);
24+
const tokens = parseAccessPathTokens(path);
25+
26+
if (tokens.length === 0) {
27+
return { methodName: "", path: "" };
28+
}
29+
30+
const match = tokens[0].text.match(methodTokenRegex);
31+
1532
if (match) {
16-
return { methodName: match[1], path: match[2] };
33+
return {
34+
methodName: match[1],
35+
path: tokens
36+
.slice(1)
37+
.map((token) => token.text)
38+
.join("."),
39+
};
1740
} else {
1841
return { methodName: "", path: "" };
1942
}

0 commit comments

Comments
 (0)