Skip to content

Commit

Permalink
Escape $'s in reference default values (#235)
Browse files Browse the repository at this point in the history
This escapes `$` in default values to avoid them being treated as
template literal substitutions.

Default values end up in a template literal `` `something` ``. If the
string contains `${...}` literally, they'll be treated as a
substitution. This PR escapes all `$`s to avoid this.

This bug/oversight doesn't cause problems with any _current_ values, but
will be required in 2.23.0.dev4 due to the new default value for
`output_path` fields from
pantsbuild/pants#21175.

Example of the effect (from
#234 (comment)):

```diff
- default_repr={`'${spec_path_normalized}/${target_name_normalized}${file_suffix}'`}
+ default_repr={`'\${spec_path_normalized}/\${target_name_normalized}\${file_suffix}'`}
```
  • Loading branch information
huonw authored Jul 25, 2024
1 parent f57cee6 commit efed535
Show file tree
Hide file tree
Showing 39 changed files with 77 additions and 72 deletions.
4 changes: 2 additions & 2 deletions docs/reference/global-options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ The path may be absolute or relative. If the directory is within the build root,
env_repr='PANTS_LOCAL_STORE_DIR'
toml_repr={`[GLOBAL]
local_store_dir = <str>`}
default_repr={`$XDG_CACHE_HOME/pants/lmdb_store`}
default_repr={`\$XDG_CACHE_HOME/pants/lmdb_store`}
>

Directory to use for the local file store, which stores the results of subprocesses run by Pants.
Expand Down Expand Up @@ -654,7 +654,7 @@ The maximum number of times to loop when `--loop` is specified.
env_repr='PANTS_NAMED_CACHES_DIR'
toml_repr={`[GLOBAL]
named_caches_dir = <str>`}
default_repr={`$XDG_CACHE_HOME/pants/named_caches`}
default_repr={`\$XDG_CACHE_HOME/pants/named_caches`}
>

Directory to use for named global caches for tools and processes with trusted, concurrency-safe caches.
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/subsystems/jvm.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ deploy_jar_exclude_files = [
'<str>',
...,
]`}
default_repr={`[\n "^META-INF/[^/]+\\.SF$",\n "^META-INF/[^/]+\\.DSA$",\n "^META-INF/[^/]+\\.RSA$",\n "META-INF/INDEX.LIST$"\n]`}
default_repr={`[\n "^META-INF/[^/]+\\.SF\$",\n "^META-INF/[^/]+\\.DSA\$",\n "^META-INF/[^/]+\\.RSA\$",\n "META-INF/INDEX.LIST\$"\n]`}
>

A list of patterns to exclude from all deploy jars. An individual deploy_jar target can also exclude other files, in addition to these, by setting its `exclude_files` field.
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/targets/vcs_version.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ All dependencies must share the same value for their `resolve` field.

<Field
type_repr={`str | None`}
default_repr={`'^(?:[\\w-]+-)?(?P<version>[vV]?\\d+(?:\\.\\d+){0,2}[^\\+]*)(?:\\+.*)?$'`}
default_repr={`'^(?:[\\w-]+-)?(?P<version>[vV]?\\d+(?:\\.\\d+){0,2}[^\\+]*)(?:\\+.*)?\$'`}
>

A Python regex string to extract the version string from a VCS tag.
Expand Down
11 changes: 8 additions & 3 deletions reference_codegen/generate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,14 @@ function convertDefault(val, type) {
val = String(val).replace(/\\n/g, "\\\\n");
}

return val
.replace(buildroot, "<buildroot>")
.replace(cachedir, "$XDG_CACHE_HOME");
return (
val
.replace(buildroot, "<buildroot>")
.replace(cachedir, "$XDG_CACHE_HOME")
// this ends up in a template literal, so if it contains literally ${something} we need to
// ensure that doesn't get interpreted as a substitution
.replace(/\$/g, "\\$")
);
}

function escape(val) {
Expand Down
8 changes: 4 additions & 4 deletions versioned_docs/version-2.0/reference/global-options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ Directory to use for local process execution sandboxing. The path may be absolut
env_repr='PANTS_LOCAL_STORE_DIR'
toml_repr={`[GLOBAL]
local_store_dir = <str>`}
default_repr={`$XDG_CACHE_HOME/pants/lmdb_store`}
default_repr={`\$XDG_CACHE_HOME/pants/lmdb_store`}
>

Directory to use for the local file store, which stores the results of subprocesses run by Pants. The path may be absolute or relative. If the directory is within the build root, be sure to include it in `--pants-ignore`.
Expand Down Expand Up @@ -361,7 +361,7 @@ The maximum number of times to loop when `--loop` is specified.
env_repr='PANTS_NAMED_CACHES_DIR'
toml_repr={`[GLOBAL]
named_caches_dir = <str>`}
default_repr={`$XDG_CACHE_HOME/pants/named_caches`}
default_repr={`\$XDG_CACHE_HOME/pants/named_caches`}
>

Directory to use for named global caches for tools and processes with trusted, concurrency-safe caches. The path may be absolute or relative. If the directory is within the build root, be sure to include it in `--pants-ignore`.
Expand Down Expand Up @@ -418,7 +418,7 @@ The name of the script or binary used to invoke Pants. Useful when printing help
env_repr='PANTS_BOOTSTRAPDIR'
toml_repr={`[GLOBAL]
pants_bootstrapdir = <dir>`}
default_repr={`$XDG_CACHE_HOME/pants`}
default_repr={`\$XDG_CACHE_HOME/pants`}
>

Unused. Will be deprecated in 2.1.0.
Expand Down Expand Up @@ -718,7 +718,7 @@ Override config with values from these files, using syntax matching that of `--p
env_repr='PANTS_PLUGIN_CACHE_DIR'
toml_repr={`[GLOBAL]
plugin_cache_dir = <str>`}
default_repr={`$XDG_CACHE_HOME/pants/plugins`}
default_repr={`\$XDG_CACHE_HOME/pants/plugins`}
>

Cache resolved plugin requirements here.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ None
env_repr='PANTS_COOKIES_PATH'
toml_repr={`[cookies]
path = <str>`}
default_repr={`$XDG_CACHE_HOME/pants/auth/cookies`}
default_repr={`\$XDG_CACHE_HOME/pants/auth/cookies`}
removal_version='2.1.0.dev0'
removal_hint={'The option `--cookies-path` does not do anything and the `[cookies]` subsystem will be removed.'}
>
Expand Down
8 changes: 4 additions & 4 deletions versioned_docs/version-2.1/reference/global-options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ Directory to use for local process execution sandboxing. The path may be absolut
env_repr='PANTS_LOCAL_STORE_DIR'
toml_repr={`[GLOBAL]
local_store_dir = <str>`}
default_repr={`$XDG_CACHE_HOME/pants/lmdb_store`}
default_repr={`\$XDG_CACHE_HOME/pants/lmdb_store`}
>

Directory to use for the local file store, which stores the results of subprocesses run by Pants. The path may be absolute or relative. If the directory is within the build root, be sure to include it in `--pants-ignore`.
Expand Down Expand Up @@ -361,7 +361,7 @@ The maximum number of times to loop when `--loop` is specified.
env_repr='PANTS_NAMED_CACHES_DIR'
toml_repr={`[GLOBAL]
named_caches_dir = <str>`}
default_repr={`$XDG_CACHE_HOME/pants/named_caches`}
default_repr={`\$XDG_CACHE_HOME/pants/named_caches`}
>

Directory to use for named global caches for tools and processes with trusted, concurrency-safe caches. The path may be absolute or relative. If the directory is within the build root, be sure to include it in `--pants-ignore`.
Expand Down Expand Up @@ -418,7 +418,7 @@ The name of the script or binary used to invoke Pants. Useful when printing help
env_repr='PANTS_BOOTSTRAPDIR'
toml_repr={`[GLOBAL]
pants_bootstrapdir = <dir>`}
default_repr={`$XDG_CACHE_HOME/pants`}
default_repr={`\$XDG_CACHE_HOME/pants`}
>

Unused. Will be deprecated in 2.2.0.
Expand Down Expand Up @@ -704,7 +704,7 @@ Override config with values from these files, using syntax matching that of `--p
env_repr='PANTS_PLUGIN_CACHE_DIR'
toml_repr={`[GLOBAL]
plugin_cache_dir = <str>`}
default_repr={`$XDG_CACHE_HOME/pants/plugins`}
default_repr={`\$XDG_CACHE_HOME/pants/plugins`}
>

Cache resolved plugin requirements here.
Expand Down
4 changes: 2 additions & 2 deletions versioned_docs/version-2.10/reference/global-options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ The path may be absolute or relative. If the directory is within the build root,
env_repr='PANTS_LOCAL_STORE_DIR'
toml_repr={`[GLOBAL]
local_store_dir = <str>`}
default_repr={`$XDG_CACHE_HOME/pants/lmdb_store`}
default_repr={`\$XDG_CACHE_HOME/pants/lmdb_store`}
>

Directory to use for the local file store, which stores the results of subprocesses run by Pants.
Expand Down Expand Up @@ -567,7 +567,7 @@ The maximum number of times to loop when `--loop` is specified.
env_repr='PANTS_NAMED_CACHES_DIR'
toml_repr={`[GLOBAL]
named_caches_dir = <str>`}
default_repr={`$XDG_CACHE_HOME/pants/named_caches`}
default_repr={`\$XDG_CACHE_HOME/pants/named_caches`}
>

Directory to use for named global caches for tools and processes with trusted, concurrency-safe caches.
Expand Down
4 changes: 2 additions & 2 deletions versioned_docs/version-2.11/reference/global-options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ The path may be absolute or relative. If the directory is within the build root,
env_repr='PANTS_LOCAL_STORE_DIR'
toml_repr={`[GLOBAL]
local_store_dir = <str>`}
default_repr={`$XDG_CACHE_HOME/pants/lmdb_store`}
default_repr={`\$XDG_CACHE_HOME/pants/lmdb_store`}
>

Directory to use for the local file store, which stores the results of subprocesses run by Pants.
Expand Down Expand Up @@ -565,7 +565,7 @@ The maximum number of times to loop when `--loop` is specified.
env_repr='PANTS_NAMED_CACHES_DIR'
toml_repr={`[GLOBAL]
named_caches_dir = <str>`}
default_repr={`$XDG_CACHE_HOME/pants/named_caches`}
default_repr={`\$XDG_CACHE_HOME/pants/named_caches`}
>

Directory to use for named global caches for tools and processes with trusted, concurrency-safe caches.
Expand Down
4 changes: 2 additions & 2 deletions versioned_docs/version-2.12/reference/global-options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ The path may be absolute or relative. If the directory is within the build root,
env_repr='PANTS_LOCAL_STORE_DIR'
toml_repr={`[GLOBAL]
local_store_dir = <str>`}
default_repr={`$XDG_CACHE_HOME/pants/lmdb_store`}
default_repr={`\$XDG_CACHE_HOME/pants/lmdb_store`}
>

Directory to use for the local file store, which stores the results of subprocesses run by Pants.
Expand Down Expand Up @@ -565,7 +565,7 @@ The maximum number of times to loop when `--loop` is specified.
env_repr='PANTS_NAMED_CACHES_DIR'
toml_repr={`[GLOBAL]
named_caches_dir = <str>`}
default_repr={`$XDG_CACHE_HOME/pants/named_caches`}
default_repr={`\$XDG_CACHE_HOME/pants/named_caches`}
>

Directory to use for named global caches for tools and processes with trusted, concurrency-safe caches.
Expand Down
4 changes: 2 additions & 2 deletions versioned_docs/version-2.13/reference/global-options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ The path may be absolute or relative. If the directory is within the build root,
env_repr='PANTS_LOCAL_STORE_DIR'
toml_repr={`[GLOBAL]
local_store_dir = <str>`}
default_repr={`$XDG_CACHE_HOME/pants/lmdb_store`}
default_repr={`\$XDG_CACHE_HOME/pants/lmdb_store`}
>

Directory to use for the local file store, which stores the results of subprocesses run by Pants.
Expand Down Expand Up @@ -610,7 +610,7 @@ The maximum number of times to loop when `--loop` is specified.
env_repr='PANTS_NAMED_CACHES_DIR'
toml_repr={`[GLOBAL]
named_caches_dir = <str>`}
default_repr={`$XDG_CACHE_HOME/pants/named_caches`}
default_repr={`\$XDG_CACHE_HOME/pants/named_caches`}
>

Directory to use for named global caches for tools and processes with trusted, concurrency-safe caches.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ All dependencies must share the same value for their `resolve` field.

<Field
type_repr={`str | None`}
default_repr={`'^(?:[\\w-]+-)?(?P<version>[vV]?\\d+(?:\\.\\d+){0,2}[^\\+]*)(?:\\+.*)?$'`}
default_repr={`'^(?:[\\w-]+-)?(?P<version>[vV]?\\d+(?:\\.\\d+){0,2}[^\\+]*)(?:\\+.*)?\$'`}
>

A Python regex string to extract the version string from a VCS tag.
Expand Down
4 changes: 2 additions & 2 deletions versioned_docs/version-2.14/reference/global-options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ The path may be absolute or relative. If the directory is within the build root,
env_repr='PANTS_LOCAL_STORE_DIR'
toml_repr={`[GLOBAL]
local_store_dir = <str>`}
default_repr={`$XDG_CACHE_HOME/pants/lmdb_store`}
default_repr={`\$XDG_CACHE_HOME/pants/lmdb_store`}
>

Directory to use for the local file store, which stores the results of subprocesses run by Pants.
Expand Down Expand Up @@ -572,7 +572,7 @@ The maximum number of times to loop when `--loop` is specified.
env_repr='PANTS_NAMED_CACHES_DIR'
toml_repr={`[GLOBAL]
named_caches_dir = <str>`}
default_repr={`$XDG_CACHE_HOME/pants/named_caches`}
default_repr={`\$XDG_CACHE_HOME/pants/named_caches`}
>

Directory to use for named global caches for tools and processes with trusted, concurrency-safe caches.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ All dependencies must share the same value for their `resolve` field.

<Field
type_repr={`str | None`}
default_repr={`'^(?:[\\w-]+-)?(?P<version>[vV]?\\d+(?:\\.\\d+){0,2}[^\\+]*)(?:\\+.*)?$'`}
default_repr={`'^(?:[\\w-]+-)?(?P<version>[vV]?\\d+(?:\\.\\d+){0,2}[^\\+]*)(?:\\+.*)?\$'`}
>

A Python regex string to extract the version string from a VCS tag.
Expand Down
4 changes: 2 additions & 2 deletions versioned_docs/version-2.15/reference/global-options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ The path may be absolute or relative. If the directory is within the build root,
env_repr='PANTS_LOCAL_STORE_DIR'
toml_repr={`[GLOBAL]
local_store_dir = <str>`}
default_repr={`$XDG_CACHE_HOME/pants/lmdb_store`}
default_repr={`\$XDG_CACHE_HOME/pants/lmdb_store`}
>

Directory to use for the local file store, which stores the results of subprocesses run by Pants.
Expand Down Expand Up @@ -592,7 +592,7 @@ The maximum number of times to loop when `--loop` is specified.
env_repr='PANTS_NAMED_CACHES_DIR'
toml_repr={`[GLOBAL]
named_caches_dir = <str>`}
default_repr={`$XDG_CACHE_HOME/pants/named_caches`}
default_repr={`\$XDG_CACHE_HOME/pants/named_caches`}
>

Directory to use for named global caches for tools and processes with trusted, concurrency-safe caches.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ All dependencies must share the same value for their `resolve` field.

<Field
type_repr={`str | None`}
default_repr={`'^(?:[\\w-]+-)?(?P<version>[vV]?\\d+(?:\\.\\d+){0,2}[^\\+]*)(?:\\+.*)?$'`}
default_repr={`'^(?:[\\w-]+-)?(?P<version>[vV]?\\d+(?:\\.\\d+){0,2}[^\\+]*)(?:\\+.*)?\$'`}
>

A Python regex string to extract the version string from a VCS tag.
Expand Down
4 changes: 2 additions & 2 deletions versioned_docs/version-2.16/reference/global-options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ The path may be absolute or relative. If the directory is within the build root,
env_repr='PANTS_LOCAL_STORE_DIR'
toml_repr={`[GLOBAL]
local_store_dir = <str>`}
default_repr={`$XDG_CACHE_HOME/pants/lmdb_store`}
default_repr={`\$XDG_CACHE_HOME/pants/lmdb_store`}
>

Directory to use for the local file store, which stores the results of subprocesses run by Pants.
Expand Down Expand Up @@ -592,7 +592,7 @@ The maximum number of times to loop when `--loop` is specified.
env_repr='PANTS_NAMED_CACHES_DIR'
toml_repr={`[GLOBAL]
named_caches_dir = <str>`}
default_repr={`$XDG_CACHE_HOME/pants/named_caches`}
default_repr={`\$XDG_CACHE_HOME/pants/named_caches`}
>

Directory to use for named global caches for tools and processes with trusted, concurrency-safe caches.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ All dependencies must share the same value for their `resolve` field.

<Field
type_repr={`str | None`}
default_repr={`'^(?:[\\w-]+-)?(?P<version>[vV]?\\d+(?:\\.\\d+){0,2}[^\\+]*)(?:\\+.*)?$'`}
default_repr={`'^(?:[\\w-]+-)?(?P<version>[vV]?\\d+(?:\\.\\d+){0,2}[^\\+]*)(?:\\+.*)?\$'`}
>

A Python regex string to extract the version string from a VCS tag.
Expand Down
4 changes: 2 additions & 2 deletions versioned_docs/version-2.17/reference/global-options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ The path may be absolute or relative. If the directory is within the build root,
env_repr='PANTS_LOCAL_STORE_DIR'
toml_repr={`[GLOBAL]
local_store_dir = <str>`}
default_repr={`$XDG_CACHE_HOME/pants/lmdb_store`}
default_repr={`\$XDG_CACHE_HOME/pants/lmdb_store`}
>

Directory to use for the local file store, which stores the results of subprocesses run by Pants.
Expand Down Expand Up @@ -592,7 +592,7 @@ The maximum number of times to loop when `--loop` is specified.
env_repr='PANTS_NAMED_CACHES_DIR'
toml_repr={`[GLOBAL]
named_caches_dir = <str>`}
default_repr={`$XDG_CACHE_HOME/pants/named_caches`}
default_repr={`\$XDG_CACHE_HOME/pants/named_caches`}
>

Directory to use for named global caches for tools and processes with trusted, concurrency-safe caches.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ All dependencies must share the same value for their `resolve` field.

<Field
type_repr={`str | None`}
default_repr={`'^(?:[\\w-]+-)?(?P<version>[vV]?\\d+(?:\\.\\d+){0,2}[^\\+]*)(?:\\+.*)?$'`}
default_repr={`'^(?:[\\w-]+-)?(?P<version>[vV]?\\d+(?:\\.\\d+){0,2}[^\\+]*)(?:\\+.*)?\$'`}
>

A Python regex string to extract the version string from a VCS tag.
Expand Down
4 changes: 2 additions & 2 deletions versioned_docs/version-2.18/reference/global-options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ The path may be absolute or relative. If the directory is within the build root,
env_repr='PANTS_LOCAL_STORE_DIR'
toml_repr={`[GLOBAL]
local_store_dir = <str>`}
default_repr={`$XDG_CACHE_HOME/pants/lmdb_store`}
default_repr={`\$XDG_CACHE_HOME/pants/lmdb_store`}
>

Directory to use for the local file store, which stores the results of subprocesses run by Pants.
Expand Down Expand Up @@ -592,7 +592,7 @@ The maximum number of times to loop when `--loop` is specified.
env_repr='PANTS_NAMED_CACHES_DIR'
toml_repr={`[GLOBAL]
named_caches_dir = <str>`}
default_repr={`$XDG_CACHE_HOME/pants/named_caches`}
default_repr={`\$XDG_CACHE_HOME/pants/named_caches`}
>

Directory to use for named global caches for tools and processes with trusted, concurrency-safe caches.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ All dependencies must share the same value for their `resolve` field.

<Field
type_repr={`str | None`}
default_repr={`'^(?:[\\w-]+-)?(?P<version>[vV]?\\d+(?:\\.\\d+){0,2}[^\\+]*)(?:\\+.*)?$'`}
default_repr={`'^(?:[\\w-]+-)?(?P<version>[vV]?\\d+(?:\\.\\d+){0,2}[^\\+]*)(?:\\+.*)?\$'`}
>

A Python regex string to extract the version string from a VCS tag.
Expand Down
4 changes: 2 additions & 2 deletions versioned_docs/version-2.19/reference/global-options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ The path may be absolute or relative. If the directory is within the build root,
env_repr='PANTS_LOCAL_STORE_DIR'
toml_repr={`[GLOBAL]
local_store_dir = <str>`}
default_repr={`$XDG_CACHE_HOME/pants/lmdb_store`}
default_repr={`\$XDG_CACHE_HOME/pants/lmdb_store`}
>

Directory to use for the local file store, which stores the results of subprocesses run by Pants.
Expand Down Expand Up @@ -592,7 +592,7 @@ The maximum number of times to loop when `--loop` is specified.
env_repr='PANTS_NAMED_CACHES_DIR'
toml_repr={`[GLOBAL]
named_caches_dir = <str>`}
default_repr={`$XDG_CACHE_HOME/pants/named_caches`}
default_repr={`\$XDG_CACHE_HOME/pants/named_caches`}
>

Directory to use for named global caches for tools and processes with trusted, concurrency-safe caches.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ All dependencies must share the same value for their `resolve` field.

<Field
type_repr={`str | None`}
default_repr={`'^(?:[\\w-]+-)?(?P<version>[vV]?\\d+(?:\\.\\d+){0,2}[^\\+]*)(?:\\+.*)?$'`}
default_repr={`'^(?:[\\w-]+-)?(?P<version>[vV]?\\d+(?:\\.\\d+){0,2}[^\\+]*)(?:\\+.*)?\$'`}
>

A Python regex string to extract the version string from a VCS tag.
Expand Down
Loading

0 comments on commit efed535

Please sign in to comment.