Skip to content

Commit

Permalink
Add 0 to allowed package name characters (#364)
Browse files Browse the repository at this point in the history
* Add 0 to allowed package name characters (#1)

For some unknown reason, `0` is the only alphanumeric character that wasn't recognized as in a package name. This led to odd scenarios that when you tried to compile code that had a `0` in the package name, the kotlin builder would package the code as the string before the `0` which led to some problems in auto-generated code.

* Add Test

* Fix missing colon

Co-authored-by: justhecuke <[email protected]>
  • Loading branch information
justhecuke and justhecuke authored Sep 9, 2020
1 parent 4cfd995 commit 73c5df8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class SourceJarCreator(
private const val BL = """\p{Blank}*"""
private const val COM_BL = """$BL(?:/\*[^\n]*\*/$BL)*"""
private val PKG_PATTERN: Pattern =
Pattern.compile("""^${COM_BL}package$COM_BL([a-zA-Z1-9._]+)$COM_BL(?:;?.*)$""")
Pattern.compile("""^${COM_BL}package$COM_BL([a-zA-Z0-9._]+)$COM_BL(?:;?.*)$""")

@JvmStatic
fun extractPackage(line: String): String? =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,16 @@ public void testPackageNameRegex() {
subj.that(pkg).isEqualTo(expectedPackage);
});
}

@Test
public void testPackageNameRegexWithZero() {
cases.forEach(
(testCase) -> {
testCase = testCase.replace("some1", "some0");
String pkg = SourceJarCreator.Companion.extractPackage(testCase);
StandardSubjectBuilder subj = assertWithMessage("positive test case: " + testCase);
subj.that(pkg).isNotNull();
subj.that(pkg).isEqualTo("iO.some0.package");
});
}
}

0 comments on commit 73c5df8

Please sign in to comment.