Skip to content

Commit 097cefa

Browse files
Strum355claude
andcommitted
refactor: replace regex with XMLParser in parseMavenModuleList
XMLParser is already imported in the file — reuse it instead of a hand-rolled regex to parse Maven's <strings><string>…</string></strings> output. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 933dfc1 commit 097cefa

2 files changed

Lines changed: 7 additions & 11 deletions

File tree

src/providers/java_maven.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -401,12 +401,10 @@ function listMavenModules(dir, mvnBin) {
401401
* @returns {string[]}
402402
*/
403403
function parseMavenModuleList(raw) {
404-
const modules = []
405-
const re = /<string>(.+?)<\/string>/g
406-
let m
407-
while ((m = re.exec(raw)) !== null) {
408-
const val = m[1].trim()
409-
if (val) modules.push(val)
410-
}
411-
return modules
404+
const parser = new XMLParser()
405+
const parsed = parser.parse(raw)
406+
const entries = parsed?.strings?.string
407+
if (!entries) { return [] }
408+
const list = Array.isArray(entries) ? entries : [entries]
409+
return list.map(s => String(s).trim()).filter(Boolean)
412410
}

test/providers/workspace.test.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,7 @@ suite('discoverWorkspaceCrates', () => {
189189
})
190190
})
191191

192-
suite('discoverMavenModules', function () {
193-
this.timeout(60_000)
194-
192+
suite('discoverMavenModules', () => {
195193
test('returns empty when no pom.xml at root', async () => {
196194
const result = await discoverMavenModules('test/providers/tst_manifests/npm')
197195
expect(result).to.be.an('array')

0 commit comments

Comments
 (0)