Repository navigation
fix(parser): strip unified diff timestamps without timezone - #611
Open
hieuvu0611 wants to merge 1 commit into
Open
hieuvu0611 wants to merge 1 commit into
hieuvu0611 wants to merge 1 commit into
Conversation
Make the trailing numeric timezone optional in getHeaderFilename so unified diff headers produced by BSD/macOS diff -u (which omit both fractional seconds and timezone offsets) are stripped cleanly without truncating filenames that contain date-like substrings. Fixes rtfpessoa#557 Signed-off-by: hieuvu0611 <162115380+hieuvu0611@users.noreply.github.com>
Owner
|
Thanks for fixing #557! I reproduced the issue with macOS Could you require a literal tab before the newly supported timezone-less timestamp? With diff -u -L 'snapshot 2025-04-06 13:33:10' \
-L 'snapshot 2025-04-07 09:10:40' old.js new.js
Please add a regression test for this case and keep the existing GNU timestamp handling unchanged. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #557
Summary
/usr/bin/diff -u(which omit fractional seconds and numeric timezone offsets, e.g.--- file1.js\t2025-04-06 13:33:10).diff -utimestamps (with fractional seconds and numeric timezone offsets), Git diffs (isGitDiff), quoted filenames, and filenames containing date substrings followed by an extension.Root Cause
In
getHeaderFilename(src/diff-parser.ts), the unified diff timestamp regex required a trailing numeric timezone offset ([+-]\d{4}.*$). Standard BSD/macOSdiff -uheaders omit both fractional seconds and timezone offsets, so the timestamp stayed attached tooldName/newNameand broke file extension detection forlanguage.Changes
src/diff-parser.ts: Make the trailing numeric timezone portion optional ((?: [+-]\d{4}.*)?$) ingetHeaderFilenamewhile anchoring the timestamp to end-of-line when no timezone is present.src/__tests__/diff-parser-tests.ts: Add unit tests covering:file1.js\t2025-04-06 13:33:10)2025-04-06 13:33:10.123456)backup 2025-04-06 13:33:10.log)Verification
format:check), ESLint (lint:check), README TOC checks (node --test scripts/update-readme-toc-checks.mjs— 6/6 passed), full build (CSS, CommonJS, ESM, webpack bundles, website), and Jest coverage (jest --coverage— 12/12 suites, 142/142 tests, 76/76 snapshots passed).lib/diff2html.jsoutput directly against real macOS/usr/bin/diff -u(Apple diff (based on FreeBSD diff)).v24.4.1/ npm11.4.2(CI validates the Node22.23.5/24.22.3/26.13.1+ npm12.2.3matrix).