Skip to content

Commit

Permalink
fix: escape | using \\ in commit messages
Browse files Browse the repository at this point in the history
  • Loading branch information
jamacku committed Jan 19, 2024
1 parent 7f10fa8 commit 69c703f
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 10 deletions.
5 changes: 3 additions & 2 deletions dist/commit.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/commit.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/util.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions dist/util.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/util.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions src/commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Endpoints } from '@octokit/types';
import { z } from 'zod';

import { SingleCommitMetadata } from './schema';
import { escape } from './util';

// subset of Endpoints['GET /repos/{owner}/{repo}/commits']['response']['data'][number]
const commitDataSchema = z.object({
Expand All @@ -25,8 +26,8 @@ export class Commit {
this.sha = parsedData.sha;
this.url = parsedData.html_url;
this.message = {
title: this.getTitle(parsedData.commit.message),
body: parsedData.commit.message,
title: escape(this.getTitle(parsedData.commit.message)),
body: escape(parsedData.commit.message),
cherryPick: this.getCherryPicks(parsedData.commit.message),
};
}
Expand Down
3 changes: 3 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function escape(str: string): string {
return str.replace('|', '\\|');
}
10 changes: 10 additions & 0 deletions test/unit/util.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { describe, expect, test } from 'vitest';

import { escape } from '../../src/util';

describe('Test utility functions', () => {
test('escape() can escape string', () => {
expect(escape('abc|def')).toBe('abc\\|def');
expect(escape('abcdef')).toBe('abcdef');
});
});

0 comments on commit 69c703f

Please sign in to comment.