Skip to content

feat: accept RegExp values in Expression/thenElse for CORS options - #1944

Open
IzaakGough wants to merge 4 commits into
masterfrom
@invertase/feat-accept-RegExp-values-in-Expression-for-cors-options
Open

feat: accept RegExp values in Expression/thenElse for CORS options#1944
IzaakGough wants to merge 4 commits into
masterfrom
@invertase/feat-accept-RegExp-values-in-Expression-for-cors-options

Conversation

@IzaakGough

@IzaakGough IzaakGough commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Fixes #1943

Expression<T> was constrained to string | number | boolean | string[], so a param ternary could not select between RegExp values even though cors accepts them. Users hit a type error when writing something like params.defineBoolean("X").thenElse(/a\.com$/, /b\.com$/) for a v2 HTTPS function's cors option.

This widens the Expression type parameter to a new exported ExpressionValue union that also covers RegExp and Array<string | RegExp>, adds those expression forms to CorsOption, and fixes CEL serialization so a RegExp is emitted as its string form rather than being dropped by JSON.stringify (which turns /foo/ into {}).

relnote: none

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request extends the Expression type and related helper functions to support RegExp and Array<string | RegExp> types, enabling dynamic selection of CORS origins via ternary expressions. It also updates the cors option in HTTPS options to use the shared CorsOption type and adds comprehensive unit tests. However, a high-severity issue was identified in src/params/types.ts where a single RegExp (not wrapped in an array) falls through to the default else block in refOf, resulting in an unquoted string representation that is invalid in CEL. A suggestion has been provided to explicitly handle RegExp and wrap its string representation in JSON.stringify.

Comment thread src/params/types.ts
A single RegExp (not wrapped in an array) passed to thenElse fell
through to arg.toString(), producing an unquoted /pattern/ in the
generated CEL string, which is invalid and fails at deploy time.
@IzaakGough
IzaakGough marked this pull request as ready for review August 6, 2026 12:25
Replace the eight inline copies of the Expression type bound with a
single exported ExpressionValue alias, so future additions to the set of
values an Expression can resolve to only need editing in one place.

Also close two gaps in the new tests:
- the nested thenElse case resolved the outer true branch, so the nested
  expression was never evaluated. Drive it from the false branch instead
  and assert both inner branches.
- the onRequest CORS case only asserted the true branch, so an
  implementation that always returned ifTrue would have passed. Add the
  false-branch case, asserting the non-matching origin is not allowed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Params CompareExpression .thenElse does not support RegExp as value, therefore disallows the use of RegExp values for CORS options

2 participants