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

Butterfly CLI allows escaped semicolons and equals as extension property value when passed using -p #361

Merged
merged 1 commit into from
Oct 28, 2020
Merged
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 @@ -155,7 +155,8 @@ ButterflyCliRun run(File butterflyHome, String butterflyBanner) {
try {
if (optionSet.has(CLI_OPTION_INLINE_PROPERTIES)) {
String inlineProperties = (String) optionSet.valueOf(CLI_OPTION_INLINE_PROPERTIES);
try (StringReader stringReader = new StringReader(inlineProperties.replace(';', '\n'))) {
// Regex to ignore escaped semi-colons
try (StringReader stringReader = new StringReader(inlineProperties.replaceAll("(?<!\\\\);", "\n"))) {
properties.load(stringReader);
}
} else if (optionSet.has(CLI_OPTION_PROPERTIES_FILE)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.paypal.butterfly.cli;

import org.testng.annotations.Test;

import com.paypal.butterfly.api.TransformationRequest;
import com.paypal.butterfly.api.TransformationResult;
import com.paypal.butterfly.api.Configuration;

import java.util.Properties;
import java.io.File;
import java.net.URISyntaxException;

import static org.testng.Assert.*;

/**
* Test for ButterflyCliRunner
*/
public class ButterflyCliRunnerTest {

// Test for parsing argument value for CLI option -p
@Test
public void testInlineProperties() throws URISyntaxException{
String sampleAppPath = new File(this.getClass().getResource("/sample_app").toURI()).getAbsolutePath();
ButterflyCliRun run = new ButterflyCliApp().run(sampleAppPath,"-p", "firstkey=firstvalue;secondkey=secondvalue");
Properties properties = run.getTransformationResult().getTransformationRequest().getConfiguration().getProperties();
assertEquals(run.getExitStatus(), 0);
assertEquals(run.getInputArguments(), new String[]{sampleAppPath, "-p","firstkey=firstvalue;secondkey=secondvalue"});
assertEquals(properties.get("firstkey"),"firstvalue");
assertEquals(properties.get("secondkey"),"secondvalue");

}

// Test for parsing argument value for CLI option -p
@Test
public void testInlinePropertiesWithEscapedSemicolon() throws URISyntaxException{
// Test with escaped ';' in the value
String sampleAppPath = new File(this.getClass().getResource("/sample_app").toURI()).getAbsolutePath();
ButterflyCliRun run = new ButterflyCliApp().run(sampleAppPath,"-p", "firstkey=first\\;value;secondkey=second\\;value");
Properties properties = run.getTransformationResult().getTransformationRequest().getConfiguration().getProperties();
assertEquals(run.getExitStatus(), 0);
assertEquals(run.getInputArguments(), new String[]{sampleAppPath, "-p","firstkey=first\\;value;secondkey=second\\;value"});
assertEquals(properties.get("firstkey"),"first;value");
assertEquals(properties.get("secondkey"),"second;value");
}

// Test for parsing argument value for CLI option -p
@Test
public void testInlinePropertiesWithEscapedEqualSign() throws URISyntaxException{
// Test with escaped '=' in the value
String sampleAppPath = new File(this.getClass().getResource("/sample_app").toURI()).getAbsolutePath();
ButterflyCliRun run = new ButterflyCliApp().run(sampleAppPath,"-p", "firstkey=first\\=value;secondkey=second\\=value");
Properties properties = run.getTransformationResult().getTransformationRequest().getConfiguration().getProperties();
assertEquals(run.getExitStatus(), 0);
assertEquals(run.getInputArguments(), new String[]{sampleAppPath, "-p","firstkey=first\\=value;secondkey=second\\=value"});
assertEquals(properties.get("firstkey"),"first=value");
assertEquals(properties.get("secondkey"),"second=value");
}
}