Skip to content

Commit

Permalink
Merge pull request #5321 from bjhargrave/issues/5318
Browse files Browse the repository at this point in the history
repository: Detect recursive macro expansion in pom properties
  • Loading branch information
bjhargrave committed Jul 16, 2022
2 parents 5af734c + d3b1a8d commit 86b426d
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion biz.aQute.repository/src/aQute/maven/provider/POM.java
Expand Up @@ -357,14 +357,25 @@ private String getOrSetNoInheritance(String key, String deflt) {
private final static Pattern MACRO_P = Pattern.compile("\\$\\{(?<prop>(?<env>env\\.)?(?<key>[-.$\\w]+))\\}");

private String replaceMacros(String value) {
return replaceMacros0(value, new HashSet<>());
}

private String replaceMacros0(String value, Set<String> processing) {
Matcher m = MACRO_P.matcher(value);
StringBuilder sb = new StringBuilder();
int start = 0;
for (; m.find(); start = m.end()) {
String key = m.group("key");
String property = (m.group("env") != null) ? System.getenv(key) : this.properties.getProperty(key);
if (property != null && property.indexOf('$') >= 0) {
property = replaceMacros(property);
if (processing.add(property)) { // not currently processing
String processed = replaceMacros0(property, processing);
processing.remove(property);
property = processed;
} else {
l.debug("Recursive property in {} : key {}", this, m.group("prop"));
property = m.group(0);
}
}
if (property == null) {
l.debug("Undefined property in {} : key {}", this, m.group("prop"));
Expand Down

0 comments on commit 86b426d

Please sign in to comment.