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

repository: Detect recursive macro expansion in pom properties #5321

Merged
merged 1 commit into from Jul 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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