Fix doc.file() throwing when the same in-memory attachment is added twice - #1781
Merged
blikblum merged 1 commit intoAug 25, 2026
Conversation
…wice The deduplication check dereferenced Params.CreationDate unguarded, and the ModDate comparison below it covered only the case where both sides were absent, so an asymmetric absence threw there as well. A source that is not read from disk - an ArrayBuffer, a Uint8Array or a data URL - carries no file system timestamps, so embedding one twice under the same name threw TypeError instead of reusing the existing reference.
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.
doc.file()reuses an existing reference when the same attachment is embeddedtwice, comparing metadata in
isEqual(). That comparison dereferencedParams.CreationDateunguarded, and theModDatecomparison below it coveredonly the case where both sides were absent — so an asymmetric absence threw
there as well.
CreationDate/ModDateare set only in thefs.statSync(src)branch, so asource that is not read from disk — an
ArrayBuffer, aUint8Arrayor a dataURL — has neither:
Where it came from
The unguarded
.getTime()comparison arrived in #1544, which fixed a real bug —the dates were being compared by identity, so two equal dates never matched.
bcc64c2later added a guard to theModDateline for the case where bothsides are absent, which is why only
CreationDatelooks obviously unguardedtoday.
The fix
Both dates now go through one helper. Two absent dates match; an absent date
never matches a present one.
Asymmetric absence returning
falseis the correct answer rather than merelythe safe one: the dates are written into the EmbeddedFile stream dictionary, so
reusing the first reference would silently discard the
creationDatethe secondcaller passed.
No non-throwing path changes result — the only behaviour that moves is the one
that previously threw.
Tests
3 added, all 3 fail on master, at three distinct positions in
isEqual(bothCreationDateoperands and theModDateone). They discriminate rather thanjust proving "no throw": the dedup case asserts both filespecs point at the same
/Freference, and the two asymmetric cases assert that two separate streams areemitted.
Unit suite 431/431.