fix(if): collect annotations from "if" without "then"/"else"#2639
Open
spokodev wants to merge 1 commit into
Open
fix(if): collect annotations from "if" without "then"/"else"#2639spokodev wants to merge 1 commit into
spokodev wants to merge 1 commit into
Conversation
When "then" and "else" are both absent the "if" assertion is ignored, but its annotations must still be collected when the instance matches "if", so that adjacent "unevaluatedItems"/"unevaluatedProperties" can see items and properties evaluated inside "if". The code returned before evaluating the "if" subschema, discarding those annotations. Evaluate the "if" subschema and merge its evaluated props/items on success. The result names are declared up front so they keep their initial value (0 / no properties) when "if" does not match, matching the JSON Schema Test Suite cases "can see annotations from if without then and else".
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.
Problem
Buffer#write(string, offset, length, encoding)with an explicitlengthsmaller than the next character's byte length writes a partial, corrupt multibyte sequence and over-reports the byte count.The Node docs state: "If
bufdid not contain enough space to fit the entire string, only part ofstringwill be written. However, partially encoded characters will not be written." The return value counts only complete characters.Repro (node Buffer oracle vs this shim)
Root cause
utf8Writeanducs2Writepassedbuf.length - offset(the whole remaining buffer) as the byte cap toutf8ToBytes/utf16leToBytes, ignoring the explicitlength:So the encoders always generated the full multibyte sequence for the next character, and
blitBufferthen copied onlylengthbytes of it, truncating the character mid-sequence and returning the truncated byte count.utf8ToBytesandutf16leToBytesalready cap output atomically per character via theirunitsargument (a multibyte char is pushed only if all of its bytes fit). Passing the effectivelengthas that cap makes the encoder drop an incomplete trailing character instead of emitting a partial one.Fix
Verification
test/write.jsasserting node parity for the cases above. It fails onmaster(6 failing assertions) and passes with the fix.npm testreports all assertions passing.Bufferover 5 encodings, 18 strings (ASCII, multibyte, surrogate pairs, emoji, lone surrogates), offsets 0 to 4, and lengths 0 to 12 (5940 cases): zero mismatches in return value and buffer contents.Closed issue #48 covered the implicit length case (a buffer too small for the whole string, no
lengthargument); that path was already fixed by thebuf.length - offsetcap. This is the distinct case where an explicitlengthargument is smaller than a single character.