Skip to content
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 @@ -121,16 +121,23 @@ public String mergeUpdatesIntoJson(String pipelineJson, Map<String, String> fqnT
return JsonUtils.asJson(pipelineNode.getCurrJsonNode());
}
fqnToJsonMap.keySet().forEach(fqn -> {
String content = fqnToJsonMap.get(fqn);
content = removeNonASCII(content);
try {
pipelineNode.replacePath(fqn, YamlUtils.readTree(fqnToJsonMap.get(fqn)).getNode().getCurrJsonNode());
pipelineNode.replacePath(fqn, YamlUtils.readTree(content).getNode().getCurrJsonNode());
} catch (IOException e) {
log.error("Could not read json provided for the fqn: " + fqn + ". Json:\n" + fqnToJsonMap.get(fqn), e);
log.error("Could not read json provided for the fqn: " + fqn + ". Json:\n" + content, e);
throw new YamlException("Could not read json provided for the fqn: " + fqn);
}
});
return JsonUtils.asJson(pipelineNode.getCurrJsonNode());
}

// Yaml Object Mapper can't handle emojis and non ascii characters
public String removeNonASCII(String content) {
return content.replaceAll("[^\\x00-\\x7F]", "");
}

public String removeFQNs(String json, List<String> toBeRemovedFQNs) {
if (EmptyPredicate.isEmpty(toBeRemovedFQNs)) {
return json;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import static io.harness.annotations.dev.HarnessTeam.PIPELINE;
import static io.harness.pms.merger.helpers.MergeHelper.mergeRuntimeInputValuesIntoOriginalYaml;
import static io.harness.rule.OwnerRule.DEV_MITTAL;
import static io.harness.rule.OwnerRule.NAMAN;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -120,6 +121,53 @@ public void testMergeYamlUpdates() throws IOException {
assertThat(noUpdatesOnYaml).isEqualTo(readFile("opa-pipeline.json"));
}

@Test
@Owner(developers = DEV_MITTAL)
@Category(UnitTests.class)
public void testMergeYamlUpdatesEmojis() throws IOException {
String filename = "opa-pipeline.yaml";
String pipeline = readFile(filename);

String fqn1 = "pipeline/stages/[0]/stage/spec/execution/steps/[0]/step/spec/connector";
String exp1 = readFile("emojiExp1.txt");

String fqn2 = "pipeline/stages/[1]/stage/spec/infrastructure/environment";
String exp2 = readFile("emojiExp2.txt");

Map<String, String> fqnToJsonMap = new HashMap<>();
fqnToJsonMap.put(fqn1, exp1);
fqnToJsonMap.put(fqn2, exp2);
String expandedPipeline = MergeHelper.mergeUpdatesIntoJson(pipeline, fqnToJsonMap);
assertThat(expandedPipeline).isNotNull();
String expandedPipelineExpected = readFile("opa-pipeline-with-expansions-no-removals.json");
assertThat(expandedPipeline).isEqualTo(expandedPipelineExpected);
YamlField yamlField = YamlUtils.readTree(expandedPipeline);
YamlNode firstExp =
yamlField.getNode().gotoPath("pipeline/stages/[0]/stage/spec/execution/steps/[0]/step/spec/connector");
YamlNode secondExp = yamlField.getNode().gotoPath("pipeline/stages/[1]/stage/spec/infrastructure/environment");
assertThat(firstExp).isNotNull();
assertThat(secondExp).isNotNull();

String noUpdates = MergeHelper.mergeUpdatesIntoJson(expandedPipeline, null);
assertThat(noUpdates).isEqualTo(expandedPipeline);

String noUpdatesOnYaml = MergeHelper.mergeUpdatesIntoJson(pipeline, null);
assertThat(noUpdatesOnYaml).isEqualTo(readFile("opa-pipeline.json"));
}

@Test
@Owner(developers = DEV_MITTAL)
@Category(UnitTests.class)
public void testRemoveNonASCII() {
String asciiString = "";
for (int i = 0; i < 128; i++) {
asciiString += (char) i;
}
assertThat(MergeHelper.removeNonASCII(asciiString)).isEqualTo(asciiString);
assertThat(MergeHelper.removeNonASCII(asciiString + "\ud330\ud803\ud823")).isEqualTo(asciiString);
assertThat(MergeHelper.removeNonASCII("\ud230\ud803\ud123" + asciiString)).isEqualTo(asciiString);
}

@Test
@Owner(developers = NAMAN)
@Category(UnitTests.class)
Expand Down
15 changes: 15 additions & 0 deletions 889-yaml-commons/src/test/resources/emojiExp1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "jira πŸ€£πŸ˜„π˜…β…πŸ˜΄βŽbasic",
"identifier": "jira_bπŸ˜¨β„¬πŸ˜asic",
"description": "",
"orgIdentifier": "def☺️😊ault",
"projectIdentifier": "Local😁😊_Dev",
"tags": {},
"type": "JiπŸ§‘β€πŸ­πŸ‘©πŸ½β€πŸ­πŸ‘¨πŸΌβ€πŸ”§ra",
"spec": {
"jiraUrl": "πŸ‘¨πŸ»β€πŸ’ΌπŸ™‡πŸ»β€β™‚οΈπŸ™‡πŸ»https://harness.atlassian.net/",
"username": "namanπŸ™‡πŸ»vermah",
"passwordRef": "nvh_doπŸπ˜…πŸ€cker_pass",
"delegateSelectors": []
}
}
10 changes: 10 additions & 0 deletions 889-yaml-commons/src/test/resources/emojiExp2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"identifier": "PR_ENV",
"name": "PR ENVπ˜…πŸ˜΄πŸ˜βš‘οΈŽ",
"description": "",
"type": "PrePπŸ’πŸΌβ€β™€οΈπŸπŸ’roduction",
"accountIdentifier": "kmpySmUISimoRrJL6NL73w",
"orgIdentifier": "d🐍πŸͺ°πŸ¦„efault",
"projectIdentifier": "LocπŸΏπŸ€πŸ€al_Dev",
"tags": {}
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ This repo contains code used in the [Harness CD Community Edition](https://githu

harness-core Project Dev environment setup instructions
==================================================
## On MacOS
## On MacOSxf f

### Prerequisities
1. Install Homebrew:
Expand Down Expand Up @@ -652,4 +652,4 @@ We are already using logback framework in our application, so it is simple to en
1. Create a new JIRA ticket(Don't use the feature branch).
2. Checkout the branch to hotfix on and make the changes.
3. Bump up the build number in the build.properties.
4. Create a pull request on this branch and master as well, make sure you merge them on master within the next 3 4 hours.
4. Create a pull request on this branch and master as well, make sure you merge them on master within the next 3 4 hours.