Skip to content

Commit ce2dd01

Browse files
fix: github push (#70)
1 parent 64e24b8 commit ce2dd01

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

src/utils/trimEndChar.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export function trimEndChar(str: string, char: string): string {
2+
if (!char || char.length !== 1) {
3+
throw new Error("trimEndChar expects a single character.")
4+
}
5+
6+
let end = str.length
7+
while (end > 0 && str[end - 1] === char) {
8+
end--
9+
}
10+
11+
return str.slice(0, end)
12+
}

src/wire/parseRefsAdResponse.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { Buffer } from 'buffer'
22
import { EmptyServerResponseError } from '../errors/EmptyServerResponseError'
3-
import { ParseError } from '../errors/ParseError'
43
import { GitPktLine } from '../models/GitPktLine'
4+
import { ParseError } from '../errors/ParseError'
5+
import { trimEndChar } from '../utils/trimEndChar'
56

67
/** @internal */
78
export type RemoteHTTPV1 = {
@@ -89,7 +90,7 @@ export async function parseRefsAdResponse(
8990
}
9091

9192
function splitAndAssert(line: string, sep: string, expected: string) {
92-
const split = line.trim().split(sep)
93+
const split = trimEndChar(line.trim(), '\x00').split(sep)
9394
if (split.length !== 2) {
9495
throw new ParseError(expected, line)
9596
}

tests/utils-trimEndChar.test.ts

1.43 KB
Binary file not shown.

0 commit comments

Comments
 (0)