handle starting and ending whitespace in song regex#11158
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hotfixes song literal parsing in the Blockly music editor field so that song hex\...`` template literals can be recognized even when formatting introduces extra whitespace/newlines at the start/end of the literal contents.
Changes:
- Relax the
hex\...`` parsing regex in the music editor field to allow whitespace immediately inside the backticks.
Comments suppressed due to low confidence (1)
pxtblocks/fields/field_musiceditor.ts:45
- This change adjusts parsing behavior for song hex literals but doesn’t appear to add coverage to ensure decompilation/block loading succeeds for
hextemplate literals that include leading/trailing (and potentially embedded) whitespace/newlines. Please add a regression test (likely undertests/decompile-test/cases/) that round-trips a multilinehexsong literal back into blocks without producing a grey/invalid field.
const match = /^\s*hex\s*`\s*([a-fA-F0-9]+)\s*`\s*(?:;?)\s*$/.exec(text);
if (match) {
song = pxt.assets.music.decodeSongFromHex(match[1]);
jwunderl
approved these changes
Mar 2, 2026
riknoll
added a commit
that referenced
this pull request
Mar 3, 2026
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 the issue reported here and here
the issue here is that somehow some newlines are getting inserted into the hex literals we generate for songs. i don't know if the users did this, or maybe we have some logic in our formatter that tries to format images, but in any case the easiest fix is to just handle it in the regex here.
not sure why people are reporting this now, because AFAIK nothing related to this was changed by the recent release at all. still, should probably hotfix this.