Skip to content

Commit f5a0bc5

Browse files
sunnylqmclaude
andcommitted
Address review feedback and fix Windows prebuild
- Reject negative numeric strings in cover fields: strtoull wraps "-1" to UINT64_MAX (and e.g. "-18446744073709551615" silently to 1); add a regression test - Fix stale README note: hdp patch auto-detects both diff formats - Install node-gyp globally on Windows runners: bun creates exe shims while prebuildify spawns node-gyp.cmd, so the prebuild step failed Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 5b99ef2 commit f5a0bc5

5 files changed

Lines changed: 17 additions & 3 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ jobs:
2727
- uses: oven-sh/setup-bun@v2
2828
with:
2929
bun-version: latest
30+
# bun 在 Windows 上生成 exe shim,而 prebuildify 硬编码 spawn node-gyp.cmd
31+
- if: runner.os == 'Windows'
32+
run: npm install -g node-gyp
3033
- run: bun install --ignore-scripts
3134
- run: bun run prebuild
3235
- run: node test/test.js

.github/workflows/publish.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ jobs:
3434
- uses: oven-sh/setup-bun@v2
3535
with:
3636
bun-version: latest
37+
# bun 在 Windows 上生成 exe shim,而 prebuildify 硬编码 spawn node-gyp.cmd
38+
- if: runner.os == 'Windows'
39+
run: npm install -g node-gyp
3740
- run: bun install --ignore-scripts
3841
- run: bun run prebuild
3942
- run: node test/test.js

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ hdp diff <oldFile> <newFile> <outDiff>
109109
hdp patch <oldFile> <diffFile> <outNew>
110110
```
111111

112-
Note: `hdp patch` applies diffs created by `hdp diff` (streaming format). Diffs
113-
created by the in-memory `diff()` / `diffWithCovers()` APIs must be applied with
114-
`patch()` or `patchSingleStream()` instead.
112+
Note: `hdp patch` auto-detects the diff format by its header, so it can apply
113+
both streaming diffs created by `hdp diff` and single-compressed diffs created
114+
by the in-memory `diff()` / `diffWithCovers()` APIs.
115115

116116
## License
117117

src/main.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ namespace hdiffpatchNode
4242

4343
inline bool parseUint64String(const std::string& value, uint64_t* out) {
4444
if (value.empty()) return false;
45+
// strtoull 会接受前导 '-' 并做二补回绕("-1" → UINT64_MAX),显式拒绝
46+
if (value.find('-') != std::string::npos) return false;
4547
errno = 0;
4648
char* end = nullptr;
4749
unsigned long long parsed = std::strtoull(value.c_str(), &end, 10);

test/test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ assert.throws(
104104
() => hdiffpatch.diffWithCovers(coverOld, coverNew, [], { mode: "invalid" }),
105105
/Invalid options.mode/
106106
);
107+
assert.throws(
108+
() => hdiffpatch.diffWithCovers(coverOld, coverNew, [
109+
{ oldPos: "-1", newPos: "0", len: "1" },
110+
]),
111+
/Invalid cover/
112+
);
107113
console.log(" ✓ diffWithCovers patch(old, diff) === new");
108114

109115
console.log("\nTest 6: Single-compressed patchSingleStream (file paths)...");

0 commit comments

Comments
 (0)