Skip to content

Commit

Permalink
fix(kubernetes): fix property parser exception (#3885) (#3894)
Browse files Browse the repository at this point in the history
when the property parser exountered a malformed it would throw an out of
bounds exception and fail. we should just skip properties with empty
values.

Fixes spinnaker/spinnaker#4629
  • Loading branch information
spinnakerbot authored and ethanfrogers committed Jul 22, 2019
1 parent 3acd86b commit 97f95e4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public static Map<String, Object> extractPropertiesFromLog(String buildLog) thro
if (MAGIC_SEARCH_PATTERN.matcher(line).find()) {
log.debug("Identified: " + line);
String[] splittedLine = line.split("=");
// if the split line doesn't match our expected length it cannot
// be parsed so we should skip it.
if (splittedLine.length != 2) {
continue;
}
final String key = splittedLine[0].replaceFirst(MAGIC_SEARCH_STRING, "").toLowerCase();
final String value = splittedLine[1].trim();
log.debug(key + ":" + value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,14 @@ class PropertyParserSpec extends Specification {
then:
properties.size() == 0
}

def "Does not attempt to parse properties with empty values"() {
String buildLog = "SPINNAKER_PROPERTY_FOO="

when:
Map<String, Object> properties = PropertyParser.extractPropertiesFromLog(buildLog)

then:
properties.size() == 0
}
}

0 comments on commit 97f95e4

Please sign in to comment.