Skip to content

Commit

Permalink
fix(server): Add Tag underscore escaping strategy (#1146)
Browse files Browse the repository at this point in the history
  • Loading branch information
Snarr authored Nov 21, 2024
1 parent 6473f2e commit edb33e9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,17 @@ public void initFrom(Message proto, ExecutionContext context) {
val = p.getVal();
}

// TODO: determine what escaping is necessary
public String getEscapedKey() {
return key;
return escapeString(key);
}

// TODO: determine what escaping is necessary
public String getEscapedVal() {
return val;
return escapeString(val);
}

public String escapeString(String str) {
if (str == null) return null;
return str.replace("_", "\\_");
}

public static Attribute fromProto(AttributePb p, ExecutionContext context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,12 @@ void storeLocalJsonVariablesWithUserDefinedStorageType() {
assertThat(keys)
.hasSize(13)
.anyMatch(key -> key.contains("5/test-id/0/variableName"))
.anyMatch(key -> key.contains("5/__wfSpecId_testWfSpecName/00000/00000__variableName_$.name_test"))
.anyMatch(key -> key.contains("5/__wfSpecId_testWfSpecName/00000/00000__variableName_$.age_20"))
.anyMatch(key -> key.contains("5/__wfSpecId_testWfSpecName/00000/00000__variableName_$.car.brand_Ford"))
.anyMatch(key -> key.contains("5/__wfSpecId_testWfSpecName/00000/00000__variableName\\_$.name_test"))
.anyMatch(key -> key.contains("5/__wfSpecId_testWfSpecName/00000/00000__variableName\\_$.age_20"))
.anyMatch(
key -> key.contains("5/__wfSpecId_testWfSpecName/00000/00000__variableName\\_$.car.brand_Ford"))
.anyMatch(key ->
key.contains("5/__wfSpecId_testWfSpecName/00000/00000__variableName_$.car.model_Escape"));
key.contains("5/__wfSpecId_testWfSpecName/00000/00000__variableName\\_$.car.model_Escape"));
}

@ParameterizedTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ private List<String> storedTagPrefixStoreKeys() {

@Test
void storeLongAttributeValueText() {
String expectedStoreKey = "5/__wfSpecId_testWfSpecName/00000/00000__testVariable_$.about_"
String expectedStoreKey = "5/__wfSpecId_testWfSpecName/00000/00000__testVariable\\_$.about_"
+ LHUtil.toLHDbSearchFormat("Consequat exercitation"
+ " officia ut mollit in aute amet. Consequat laborum elit id incididunt quis"
+ " aliquip pariatur magna eu velit ad dolore. Consectetur excepteur ut sit"
Expand All @@ -152,7 +152,7 @@ void storeLongAttributeValueText() {
+ " qui pariatur. Incididunt fugiat enim duis consequat mollit nisi elit"
+ " pariatur et excepteur id voluptate dolor.\r\n");

String prefixToIgnore = "5/__wfSpecId_testWfSpecName/00000/00000__testVariable_$.about_";
String prefixToIgnore = "5/__wfSpecId_testWfSpecName/00000/00000__testVariable\\_$.about_";
int ignoredLength = prefixToIgnore.length();

Assertions.assertThat(expectedStoreKey.length()).isEqualTo(64 + 16 + ignoredLength);
Expand All @@ -164,33 +164,33 @@ void storeLongAttributeValueText() {
@Test
void storeEmailAttributeValue() {
String expectedStoreKey =
"5/__wfSpecId_testWfSpecName/00000/00000__testVariable_[email protected]";
"5/__wfSpecId_testWfSpecName/00000/00000__testVariable\\_[email protected]";
Assertions.assertThat(storedTagPrefixStoreKeys()).contains(expectedStoreKey);
}

@Test
void storeInnerArrayObject() {
List<String> expectedKeys = List.of(
"5/__wfSpecId_testWfSpecName/00000/00000__testVariable_$.tags_ex",
"5/__wfSpecId_testWfSpecName/00000/00000__testVariable_$.tags_fugiat",
"5/__wfSpecId_testWfSpecName/00000/00000__testVariable_$.tags_id",
"5/__wfSpecId_testWfSpecName/00000/00000__testVariable_$.tags_labore",
"5/__wfSpecId_testWfSpecName/00000/00000__testVariable_$.tags_dolor",
"5/__wfSpecId_testWfSpecName/00000/00000__testVariable_$.tags_consectetur",
"5/__wfSpecId_testWfSpecName/00000/00000__testVariable_$.tags_veniam");
"5/__wfSpecId_testWfSpecName/00000/00000__testVariable\\_$.tags_ex",
"5/__wfSpecId_testWfSpecName/00000/00000__testVariable\\_$.tags_fugiat",
"5/__wfSpecId_testWfSpecName/00000/00000__testVariable\\_$.tags_id",
"5/__wfSpecId_testWfSpecName/00000/00000__testVariable\\_$.tags_labore",
"5/__wfSpecId_testWfSpecName/00000/00000__testVariable\\_$.tags_dolor",
"5/__wfSpecId_testWfSpecName/00000/00000__testVariable\\_$.tags_consectetur",
"5/__wfSpecId_testWfSpecName/00000/00000__testVariable\\_$.tags_veniam");
Assertions.assertThat(storedTagPrefixStoreKeys()).containsAll(expectedKeys);
}

@Test
void storeDoubleAttributeValue() {
String expectedStoreKey = "5/__wfSpecId_testWfSpecName/00000/00000__testVariable_$.balance_2759.634399439295";
String expectedStoreKey = "5/__wfSpecId_testWfSpecName/00000/00000__testVariable\\_$.balance_2759.634399439295";
Assertions.assertThat(storedTagPrefixStoreKeys()).contains(expectedStoreKey);
}

@Test
void preventStorageForNonIndexedAttributes() {
String expectedStoreKey =
"5/__wfSpecId_testWfSpecName/00000/00000__testVariable_$.registered_2018-09-02T10:37:59" + " +05:00";
"5/__wfSpecId_testWfSpecName/00000/00000__testVariable\\_$.registered_2018-09-02T10:37:59" + " +05:00";
Assertions.assertThat(storedTagPrefixStoreKeys()).doesNotContain(expectedStoreKey);
}

Expand All @@ -200,7 +200,7 @@ void storeJsonArrIndexes() {
"5/__wfSpecId_testWfSpecName/00000/00000__test_asdf",
"5/__wfSpecId_testWfSpecName/00000/00000__test_fdsa",
"5/__wfSpecId_testWfSpecName/00000/00000__test_1234",
"5/__wfSpecId_testWfSpecName/00000/00000__test_$.foo_bar");
"5/__wfSpecId_testWfSpecName/00000/00000__test\\_$.foo_bar");
Assertions.assertThat(storedTagPrefixStoreKeys()).containsAll(expectedKeys);
}
}

0 comments on commit edb33e9

Please sign in to comment.