refactor(admin): extract parsePropsParam helper for props query param#254
Open
JonasJesus42 wants to merge 2 commits into
Open
refactor(admin): extract parsePropsParam helper for props query param#254JonasJesus42 wants to merge 2 commits into
JonasJesus42 wants to merge 2 commits into
Conversation
Replace the nested try/catch decoding in render.ts with a flat, testable
parsePropsParam helper that tries each encoding strategy in order and
returns null on failure (so callers can react instead of silently getting
{}). Unify invoke.ts GET decoding on the same helper, which also adds the
previously-missing base64 fallback to /deco/invoke.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Move the loop's empty catch into a named tryOrNull helper whose sole documented job is "try or return null", and tighten the guard to reject arrays (typeof [] is "object") so only plain objects are accepted as props. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Replaces the nested
try/catchprops-decoding insrc/admin/render.tswith a flat, reusableparsePropsParamhelper (src/admin/propsParam.ts) that tries each encoding strategy — plainencodeURIComponent(JSON)and base64btoa(encodeURIComponent(JSON))— in order and returnsnullon total failure, sorender.tsnow logs a warning instead of silently rendering with{}. The helper also adds atypeof === "object"guard that rejects valid-JSON-but-not-object inputs. Theinvoke.tsGET branch now reuses the same helper, unifying both admin endpoints and adding the previously-missing base64 fallback to/deco/invoke. Verified withnpm run typecheckandnpm run build.🤖 Generated with Claude Code
Summary by cubic
Extracted a reusable props parser for admin query params that unifies decoding in
renderandinvoke, adds base64 support to/deco/invoke, and only accepts plain object props.parsePropsParaminsrc/admin/propsParam.tsthat tries URI-encoded JSON then base64(URI-encoded JSON), uses an internaltryOrNull, returnsnullon failure, and accepts only plain objects (rejects arrays/primitives).render.tsto use the helper and warn on parse failure instead of defaulting to{}.invoke.tsGET branch to reuse the helper and gain the base64 fallback.Written for commit 5411dd2. Summary will update on new commits.