Preserve unrepresentable raw action values as references#203
Open
sfly9 wants to merge 1 commit into
Open
Conversation
Decompiling a raw action parameter that doesn't match any known value shape (e.g. a third-party app's opaque struct, such as a HomeKit scene selection silently produced an empty string, discarding the underlying data with no indication anything was lost. Route these values through the existing #ref mechanism instead: register the value as a reference and emit a placeholder in the rawAction dict, with a decompWarning noting a reference was used in place of literal Cherri source. Reference hashes now also survive raw []byte (plist <data>) values, which would otherwise become an indistinguishable base64 <string> when round-tripped through JSON. Verified against a real Shortcut using a third-party app's HomeKit trigger action: the recompiled plist's parameter value is byte-for-byte identical to the original, including the binary payload. Added a tests/raw-action-variable-values.cherri case exercising a #ref used inside a rawAction() dict. EOF )
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.
Summary
Decompiling a raw action parameter whose value doesn't match any shape
decompValueObjectknows how to represent (e.g. a third-party app's opaque struct, such as a HomeKit scene selection) currently produces a silent empty string — the underlying data is discarded with no indication anything was lost. I hit this decompiling a Shortcut that uses a HomeKit trigger action.This routes those values through the existing
#refmechanism instead of discarding them:decompile.go: whendecompValueObjectcan't represent a raw action parameter, register the value as a reference and emit a${identifier}placeholder in therawActiondict, with adecompWarning(existing helper, same pattern as the one atdecompile.go:1186) noting a reference was substituted. Handles naming collisions when the same parameter key produces different values across multiple actions in the same Shortcut.raw_actions.go:${...}placeholders inside arawAction()dict now also resolve against declared#refs (only when there's no@, since variable references always use@), not just variable names.references.go: reference hashes now survive raw[]byte(plist<data>) values. JSON has no native binary type, so without this a<data>element would silently round-trip back as an indistinguishable<string>— a correctness bug in the existing file/media reference path that this change also happens to fix, even though those reference types don't currently carry byte data.Testing
go build ./...go test -run TestCherriNoSignandgo test -run TestDecomp— pass, including the new test casegolangci-lint run ./...— 22 pre-existing findings, confirmed identical (same count, same lines) on unmodifiedmain; this change introduces nonetests/raw-action-variable-values.cherriexercising a#refused inside arawAction()dict (the#refhash was generated by the compiler itself against a synthetic fixture, not hand-written)