Skip to content

Commit 5559bfc

Browse files
XmlParser: case-insensitive accept for nuget.config (#7317)
* Use case-insensitive comparison for nuget.config and packages.config in XmlParser The XmlParser.accept() method used Path.endsWith() which is case-sensitive, so files like NuGet.config or Packages.config were not recognized as XML and fell through to the PlainTextParser. Switch to equalsIgnoreCase on the file name to handle all casing variants. * Also make file extension checks case-insensitive in XmlParser Apply toLowerCase() to the extracted extension before checking against the accepted set, so files like foo.XML or proj.Csproj are correctly recognized.
1 parent 71809c7 commit 5559bfc

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

rewrite-xml/src/main/java/org/openrewrite/xml/XmlParser.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,13 @@ public boolean accept(Path path) {
117117
String p = path.toString();
118118
int dot = p.lastIndexOf('.');
119119
if (0 < dot && dot < (p.length() - 1)) {
120-
if (ACCEPTED_FILE_EXTENSIONS.contains(p.substring(dot + 1))) {
120+
if (ACCEPTED_FILE_EXTENSIONS.contains(p.substring(dot + 1).toLowerCase())) {
121121
return true;
122122
}
123123
}
124-
return path.endsWith("nuget.config") ||
125-
path.endsWith("packages.config");
124+
String fileName = path.getFileName().toString();
125+
return fileName.equalsIgnoreCase("nuget.config") ||
126+
fileName.equalsIgnoreCase("packages.config");
126127
}
127128

128129
@Override

rewrite-xml/src/test/java/org/openrewrite/xml/XmlParserTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,9 +686,15 @@ void preserveWhitespaceOnEntities() {
686686
@ParameterizedTest
687687
@ValueSource(strings = {
688688
"foo.xml",
689+
"foo.XML",
689690
"proj.csproj",
691+
"proj.Csproj",
690692
"/foo/bar/baz.jsp",
691-
"packages.config"
693+
"packages.config",
694+
"Packages.config",
695+
"nuget.config",
696+
"NuGet.config",
697+
"NuGet.Config"
692698
})
693699
void acceptWithValidPaths(String path) {
694700
assertThat(new XmlParser().accept(Path.of(path))).isTrue();

0 commit comments

Comments
 (0)