Skip to content

Commit

Permalink
fix: switch to unicode aware regex for punctuation
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanvade committed Jul 9, 2024
1 parent 44f8ad1 commit 9c27250
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion __tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ describe("index", () => {
const regex = getRegex();
const defaultRegex =
// eslint-disable-next-line no-useless-escape
/(?<=^|[a-z]-|[\s\p{Punct}&[^\-]])([A-Z][A-Z0-9_]*-\d+)(?![^\W_])(\s)+(.)+/;
/(?<=^|[a-z]-|[\s\p{P}&[^\-])([A-Z][A-Z0-9_]*-\d+)(?![^\W_])(\s)+(.)+/u;
expect(regex.length).toEqual(1);
expect(regex[0]).toEqual(defaultRegex);
expect(regex[0].test("PR-4 this is valid")).toBe(true);
Expand Down
5 changes: 3 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,12 @@ export const getPullRequestTitle = () => {

const getDefaultJiraIssueRegex = () =>
new RegExp(
"(?<=^|[a-z]-|[\\s\\p{Punct}&[^\\-]])([A-Z][A-Z0-9_]*-\\d+)(?![^\\W_])(\\s)+(.)+",
"(?<=^|[a-z]-|[\\s\\p{P}&[^\\-])([A-Z][A-Z0-9_]*-\\d+)(?![^\\W_])(\\s)+(.)+",
"u"
);

const isValidProjectKey = (projectKey: string) =>
/(?<=^|[a-z]-|[\s\p{Punct}&[^-]])([A-Z][A-Z0-9_]*)/.test(projectKey);
/(?<=^|[a-z]-|[\s\p{P}&[^-])([A-Z][A-Z0-9_]*)/u.test(projectKey);

const getRegexWithProjectKeyAndKeyAnywhereInTitle = (
projectKey: string,
Expand Down

0 comments on commit 9c27250

Please sign in to comment.