Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keep xml tag value as string when parsing pom.xml #26931

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion generators/maven/internal/xml-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ const defaultXmlCommonOptions: Partial<X2jOptions & XmlBuilderOptions> = {
ignoreAttributes: false,
attributeNamePrefix: '@@',
commentPropName: '#comment',
parseAttributeValue: false,
};

export const defaultXmlParserOptions: Partial<X2jOptions> = {
parseAttributeValue: false,
parseTagValue: false,
...defaultXmlCommonOptions,
};

Expand Down
49 changes: 49 additions & 0 deletions generators/maven/support/dependabot-maven.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* Copyright 2013-2024 the original author or authors from the JHipster project.
*
* This file is part of the JHipster project, see https://www.jhipster.tech/
* for more information.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { describe, expect } from 'esmocha';
import { parseMavenPom } from './dependabot-maven.js';

describe('parseMavenPom', () => {
it('should parse a pom file', () => {
const pomContent = `<?xml version="1.0" encoding="UTF-8"?>
<project>
<artifactId>test</artifactId>
<version>1.0</version>
<properties>
<test.version>1.0</test.version>
</properties>
</project>`;
const pom = parseMavenPom(pomContent);
expect(pom).toMatchInlineSnapshot(`
{
"?xml": {
"@@encoding": "UTF-8",
"@@version": "1.0",
},
"project": {
"artifactId": "test",
"properties": {
"test.version": "1.0",
},
"version": "1.0",
},
}
`);
});
});
5 changes: 3 additions & 2 deletions generators/maven/support/dependabot-maven.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
* limitations under the License.
*/
import { XMLParser } from 'fast-xml-parser';
import { defaultXmlParserOptions } from '../internal/xml-store.js';

/**
* Extract properties from pom content
* @param pomContent
*/
export function getPomProperties(pomContent: string): Record<string, string> {
return new XMLParser().parse(pomContent).project.properties;
return new XMLParser(defaultXmlParserOptions).parse(pomContent).project.properties;
}

export type MavenPom = {
Expand All @@ -44,7 +45,7 @@ export type MavenPomAndVersions = {
* @param fileContent
*/
export function parseMavenPom(fileContent: string): MavenPom {
return new XMLParser().parse(fileContent);
return new XMLParser(defaultXmlParserOptions).parse(fileContent);
}

/**
Expand Down
Loading