-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tycho-versions-plugin: PomUtil.expandProperties(): Quote replacements
The replacement strings passed to java.util.regex.Matcher.appendReplacement(StringBuilder, String) are to be treated literally, no regex capture groups are to be evaluated if the replacement string happens to contains '${...}'. So they must be quoted using java.util.regex.Matcher.quoteReplacement(String)
- Loading branch information
Showing
2 changed files
with
44 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
tycho-versions-plugin/src/test/java/org/eclipse/tycho/versions/pom/tests/PomUtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 SAP SE and others. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* SAP SE - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.tycho.versions.pom.tests; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
import org.eclipse.tycho.versions.pom.PomFile; | ||
import org.eclipse.tycho.versions.pom.PomUtil; | ||
import org.junit.Test; | ||
|
||
public class PomUtilTest { | ||
|
||
@Test | ||
public void expandProperties() throws Exception { | ||
String pom = """ | ||
<project> | ||
<properties> | ||
<foo> fooValue </foo> | ||
<bar>barValue</bar> | ||
</properties> | ||
</project> | ||
"""; | ||
PomFile pomFile = PomFile.read(new ByteArrayInputStream(pom.getBytes(StandardCharsets.UTF_8)), true); | ||
|
||
String expanded = PomUtil.expandProperties("${foo}-${bar}-${notFound}", pomFile.getProperties()); | ||
|
||
assertEquals("fooValue-barValue-${notFound}", expanded); | ||
} | ||
} |