diff options
author | twerth <twerth@google.com> | 2018-05-15 05:02:31 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-05-15 05:03:50 -0700 |
commit | c4f2d80270f1ce947fcf7fb0a4e5f0afb3a7062d (patch) | |
tree | 5928bf2f9d72ffc3eec0a5e08456e2574a4c2e31 /src/main/java/com/google/devtools/build/lib/cmdline | |
parent | bd16ab9454e624a26c53a0f3fb892e20fb1c36e6 (diff) |
Allow more characters in labels.
Partly addresses #374.
Specifically allow !%^`"'&;<>?[]{|} in target and package names. It's actually
simpler now to declare what we don't allow. In target names:
0-31 (control characters)
58 ':' (colon)
92 '\' (backslash)
127 (delete)
In package names:
0-31 (control characters)
58 ':' (colon)
64 '@' (at-sign)
92 '\' (backslash)
127 (delete)
- '\' is a path segment separator on Windows, and allowing it can lead to
silent output file conflicts and - therefore - data corruption. We may be
able to allow it in the future, but I didn't want to make that call.
- ':' is a special character that Bazel interprets as the package name / target
name separator.
- '@' in package names can probably be allowed; at the beginning of a label it
indicates a workspace name, but not within a segment. We actually have some
tests that disallow it specifically, but those can probably just be deleted;
however, it does require a bit of investigation, so I decided to delay that
change.
It is possible that we don't correctly escape filenames in all cases. Also note
that the shell may require escaping for specific characters, and that Bazel
treats a single '*' (star) target name specially when given on the command
line.
RELNOTES: Bazel now allows almost all 7-bit ASCII characters in labels.
PiperOrigin-RevId: 196650651
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/cmdline')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/cmdline/LabelValidator.java | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/cmdline/LabelValidator.java b/src/main/java/com/google/devtools/build/lib/cmdline/LabelValidator.java index a2f419eb23..633946c60f 100644 --- a/src/main/java/com/google/devtools/build/lib/cmdline/LabelValidator.java +++ b/src/main/java/com/google/devtools/build/lib/cmdline/LabelValidator.java @@ -24,8 +24,14 @@ import javax.annotation.Nullable; */ public final class LabelValidator { + // Target names allow all 7-bit ASCII characters except + // 0-31 (control characters) + // 58 ':' (colon) + // 92 '\' (backslash) - directory separator (on Windows); may be allowed in the future + // 127 (delete) /** Matches punctuation in target names which requires quoting in a blaze query. */ - private static final CharMatcher PUNCTUATION_REQUIRING_QUOTING = CharMatcher.anyOf("+,=~# ()$"); + private static final CharMatcher PUNCTUATION_REQUIRING_QUOTING = + CharMatcher.anyOf(" \"#$&'()*+,;<=>?[]{|}~"); /** * Matches punctuation in target names which doesn't require quoting in a blaze query. @@ -33,16 +39,21 @@ public final class LabelValidator { * Note that . is also allowed in target names, and doesn't require quoting, but has restrictions * on its surrounding characters; see {@link #validateTargetName(String)}. */ - private static final CharMatcher PUNCTUATION_NOT_REQUIRING_QUOTING = CharMatcher.anyOf("_@-"); - - /** - * Matches characters allowed in package name. - */ + private static final CharMatcher PUNCTUATION_NOT_REQUIRING_QUOTING = + CharMatcher.anyOf("!%-@^_`"); + + // Package names allow all 7-bit ASCII characters except + // 0-31 (control characters) + // 58 ':' (colon) - target name separator + // 64 '@' (at-sign) - workspace name prefix + // 92 '\' (backslash) - directory separator (on Windows); may be allowed in the future + // 127 (delete) + /** Matches characters allowed in package name. */ private static final CharMatcher ALLOWED_CHARACTERS_IN_PACKAGE_NAME = CharMatcher.inRange('0', '9') .or(CharMatcher.inRange('a', 'z')) .or(CharMatcher.inRange('A', 'Z')) - .or(CharMatcher.anyOf("/-._ $()")) + .or(CharMatcher.anyOf(" !\"#$%&'()*+,-./;<=>?[]^_`{|}~")) .precomputed(); /** @@ -59,7 +70,8 @@ public final class LabelValidator { @VisibleForTesting static final String PACKAGE_NAME_ERROR = - "package names may contain only A-Z, a-z, 0-9, '/', '-', '.', ' ', '$', '(', ')' and '_'"; + "package names may contain A-Z, a-z, 0-9, or any of ' !\"#$%&'()*+,-./;<=>?[]^_`{|}~'" + + " (most 127-bit ascii characters except 0-31, 127, ':', '@', or '\\')"; @VisibleForTesting static final String PACKAGE_NAME_DOT_ERROR = |