fix(time-signature): return NONE instead of throwing on non-matching input - #501
Open
youdie006 wants to merge 1 commit into
Open
fix(time-signature): return NONE instead of throwing on non-matching input#501youdie006 wants to merge 1 commit into
youdie006 wants to merge 1 commit into
Conversation
…input
TimeSignature.get / parse threw 'Cannot read properties of undefined (reading
split)' on any string that does not match the <n>/<n> regex - most notably 'C'
(common time), but also '', 'x', etc. In parse, const [_, up, low] =
REGEX.exec(literal) || [] yields an undefined up on a regex miss, which recurses
into the array branch where up.split('+') throws.
Add a defensive guard: when up is not a string, return the zeroed parse [0, 0],
which build() already maps to the NONE / empty signature - the same path invalid
inputs like '0/0' already take. No behavior change for valid input.
Fixes tonaljs#490
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 #490
Problem
TimeSignature.get/parsethrowTypeError: Cannot read properties of undefined (reading 'split')on any string that doesn't match the<n>/<n>regex -- most notably"C"(common time), but also"","x", etc.Root cause
In
parse,const [_, up, low] = REGEX.exec(literal) || []yields anundefinedupwhen the regex doesn't match. That recurses into the array branch whereup.split("+")(index.ts:72) throws.Fix
Add a defensive guard: when
upis not a string (regex miss), return the zeroed parse[0, 0], which the existingbuild()already maps to theNONE/ empty signature -- the same path invalid inputs like"0/0"already take. No behavior change for valid input.Tests
Added a regression test in
packages/time-signature/test.tsasserting that"C","","x","4","/","abc"do not throw and return the empty signature, and that"4/4"still parses correctly.Cannot read properties of undefined (reading 'split')error (red).This contribution was prepared with AI assistance.