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

[util] Escape path separators in batch variable keys #5597

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ variables.userLocale=ca

template-processor.resolve-bdd-variables=true

variables.scope-priority-check=should be global
batch-1.variables.scope-priority-check=should be batch
variables.scope.priority-check=should be global
batch-1.variables.scope.priority-check=should be batch

# This property is used to test HTTP retry on service unavailability
http.service-unavailable-retry.status-codes=418,502,504
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@

public class PropertyMapper implements IPropertyMapper
{
private static final String VARIABLES_PROPERTY_PREFIX = "variables.";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can't hardcode it here:

  1. util module should know nothing about engine module
  2. this adds tight coupling to property naming

please check this: c9197ca

private static final String VARIABLES_PATH_SEPARATOR_REGEX = "(?<!variables)\\.";

private final String propertyPrefixSeparator;
private final JavaPropsMapper javaPropsMapper;
private final PropertyParser propertyParser;
Expand Down Expand Up @@ -155,7 +158,15 @@ protected Map<String, String> collectObjectProperties(Map<String, String> proper
{
return properties.entrySet().stream()
.filter(e -> e.getKey().startsWith(propertyFamily))
.collect(toMap(e -> StringUtils.removeStart(e.getKey(), propertyFamily), Entry::getValue));
.collect(toMap(e -> escapePathSeparatorForVariableKey(
StringUtils.removeStart(e.getKey(), propertyFamily)), Entry::getValue));
}

private String escapePathSeparatorForVariableKey(String property)
{
return property.startsWith(VARIABLES_PROPERTY_PREFIX)
? property.replaceAll(VARIABLES_PATH_SEPARATOR_REGEX, "\0.")
: property;
}

protected String getPropertyPrefixSeparator()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 the original author or authors.
* Copyright 2019-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -106,9 +106,13 @@ void shouldMapMergedPropertiesToCollectionOfObjects() throws IOException
String addressPrefix = "address.";
String streetNameKey = "street-name";
String streetName = "Stakanalievo";
String variablesPrefix = "variables.";
String variablesKey = "compo.site.key";
String variablesValue = "value";

Map<String, String> properties = new HashMap<>(createObjectProperties(PROPERTY_PREFIX + ADMIN + '.'));
properties.put(PROPERTY_PREFIX + ADMIN + '.' + addressPrefix + streetNameKey, streetName);
properties.put(PROPERTY_PREFIX + ADMIN + '.' + variablesPrefix + variablesKey, variablesValue);
when(propertyParser.getPropertiesByPrefix(PROPERTY_PREFIX)).thenReturn(properties);

Map<String, String> baseProperties = Map.of(
Expand All @@ -120,6 +124,7 @@ void shouldMapMergedPropertiesToCollectionOfObjects() throws IOException
PropertyMappedCollection<User> result = propertyMapper.readValues(PROPERTY_PREFIX, addressPrefix,
User.class);
assertCollection(result, ADMIN);
assertEquals(variablesValue, result.getData().get(ADMIN).getVariables().get(variablesKey));
Address address = result.getData().get(ADMIN).getAddress();
assertNotNull(address);
assertEquals(streetName, address.getStreetName());
Expand Down Expand Up @@ -224,6 +229,7 @@ private static final class User
private Pattern pattern;
private Supplier<String> dob;
private Address address;
private Map<String, String> variables;

public String getFirstName()
{
Expand Down Expand Up @@ -254,6 +260,11 @@ public Address getAddress()
{
return address;
}

public Map<String, String> getVariables()
{
return variables;
}
}

private static final class Address
Expand Down
Loading