Skip to content

Commit

Permalink
Minor changes to the label parsing to match the specification more cl…
Browse files Browse the repository at this point in the history
…osely.

--
MOS_MIGRATED_REVID=102496746
  • Loading branch information
ulfjack authored and damienmg committed Sep 8, 2015
1 parent 05e2c5b commit 1540c7b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ 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("_-@");
private static final CharMatcher PUNCTUATION_NOT_REQUIRING_QUOTING = CharMatcher.anyOf("_@-");

/**
* Matches characters allowed in target names regardless of context.
Expand Down Expand Up @@ -77,7 +77,7 @@ public static String validatePackageName(String packageName) {
return PACKAGE_NAME_ERROR;
}

// Check for any character outside of [/0-9A-Z_a-z-]. Try to evaluate the
// Check for any character outside of [/0-9A-Za-z_-]. Try to evaluate the
// conditional quickly (by looking in decreasing order of character class
// likelihood).
for (int i = len - 1; i >= 0; --i) {
Expand Down Expand Up @@ -160,10 +160,12 @@ public static String validateTargetName(String targetName) {
return "target names may not contain '" + c + "'";
}
// Forbidden end chars:
if (c == '.' && targetName.endsWith("/..")) {
return "target names may not contain up-level references '..'";
} else if (c == '.' && targetName.endsWith("/.")) {
return null; // See comment above; ideally should be an error.
if (c == '.') {
if (targetName.endsWith("/..")) {
return "target names may not contain up-level references '..'";
} else if (targetName.endsWith("/.")) {
return null; // See comment above; ideally should be an error.
}
}
if (c == '/') {
return "target names may not end with '/'";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private static String validate(String name) {
return "empty workspace name";
}

// Check for any character outside of [/0-9A-Z_a-z-._]. Try to evaluate the
// Check for any character outside of [/0-9A-Za-z_.-]. Try to evaluate the
// conditional quickly (by looking in decreasing order of character class
// likelihood).
if (name.startsWith("@/") || name.endsWith("/")) {
Expand Down

0 comments on commit 1540c7b

Please sign in to comment.