Skip to content

getNameArgs in variables.js doesn't understand nested macros #21751

@calebcordry

Description

@calebcordry

We have a function export function getNameArgs that extracts the name from the arguments in our macros. encodeVars relies on this function to not encode the arguments to a macro which will later be resolved by UrlReplacementService. This does not work for nested macros and thus the arguments get encoded and everything breaks.

example:
encodeVars(SOME_MACRO(abc,123)) == SOME_MACRO(abc,123)
encodeVars(SOME_MACRO(abc, OTHER_MACRO(foo))) == SOME_MACRO(abc%2C%20OTHER_MACRO(foo))

This could be fixed by altering the regex here to be smart about nested macros.

const VARIABLE_ARGS_REGEXP = /^(?:([^\s]*)(\([^)]*\))|[^]+)$/;

cc/ @ampproject/wg-analytics

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions