Skip to content
This repository was archived by the owner on May 16, 2025. It is now read-only.

Commit f4dc31d

Browse files
committed
Don't trigger feedback/recursion on JSON-LD keywords
See https://gitlab.com/oersi/oersi-etl/-/issues/29
1 parent 0b53d78 commit f4dc31d

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

org.metafacture.fix/src/main/java/org/metafacture/metamorph/FixBuilder.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
*
5151
*/
5252
public class FixBuilder { // checkstyle-disable-line ClassDataAbstractionCoupling|ClassFanOutComplexity
53+
54+
static final String ARRAY_MARKER = "[]";
5355
private static final String FLUSH_WITH = "flushWith";
5456
private static final String RECORD = "record";
5557
private final Deque<StackFrame> stack = new LinkedList<>();
@@ -91,7 +93,7 @@ private void processBind(final Expression expression, final EList<String> params
9193
collect = createEntity(firstParam);
9294
break;
9395
case "array":
94-
collect = createEntity(firstParam + "[]");
96+
collect = createEntity(firstParam + ARRAY_MARKER);
9597
break;
9698
case "map":
9799
final NamedValuePipe enterDataMap = enterDataMap(params, false);

org.metafacture.fix/src/main/java/org/metafacture/metamorph/Metafix.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import java.io.Reader;
5858
import java.io.StringReader;
5959
import java.util.ArrayList;
60+
import java.util.Arrays;
6061
import java.util.Collection;
6162
import java.util.Collections;
6263
import java.util.Deque;
@@ -88,6 +89,12 @@ public class Metafix implements StreamPipe<StreamReceiver>, NamedValuePipe, Maps
8889
private static final InterceptorFactory NULL_INTERCEPTOR_FACTORY = new NullInterceptorFactory();
8990
private static final Map<String, String> NO_VARS = Collections.emptyMap();
9091

92+
// See https://www.w3.org/TR/json-ld11/#keywords
93+
private static final List<String> JSONLD_KEYWORDS = Arrays.asList(
94+
"@base", "@container", "@context", "@direction", "@graph", "@id", "@import", "@included", "@index", "@json",
95+
"@language", "@list", "@nest", "@none", "@prefix", "@propagate", "@protected", "@reverse", "@set", "@type",
96+
"@value", "@version", "@vocab");
97+
9198
// warning: auxiliary class WildcardRegistry in WildcardDataRegistry.java should not be accessed from outside its own source file
9299
//private final Registry<NamedValueReceiver> dataRegistry = new WildcardRegistry<>();
93100
private final Registry<NamedValueReceiver> dataRegistry = new Registry<NamedValueReceiver>() {
@@ -370,8 +377,9 @@ public void receive(final String name, final String value, final NamedValueSourc
370377
throw new IllegalArgumentException(
371378
"encountered literal with name='null'. This indicates a bug in a function or a collector.");
372379
}
373-
374-
if (name.length() != 0 && name.charAt(0) == FEEDBACK_CHAR) {
380+
final int end = Math.min(name.indexOf(flattener.getEntityMarker()), name.indexOf(FixBuilder.ARRAY_MARKER));
381+
final String firstNameSegment = end == -1 ? name : name.substring(0, end);
382+
if (name.length() != 0 && name.charAt(0) == FEEDBACK_CHAR && !JSONLD_KEYWORDS.contains(firstNameSegment)) {
375383
dispatch(name, value, null);
376384
return;
377385
}

org.metafacture.fix/src/test/java/org/metafacture/metamorph/MetafixDslTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,19 @@ public void shouldMatchCharactersInCharacterClass() {
869869
Mockito.verify(streamReceiver, Mockito.times(2)).literal(ArgumentMatchers.any(), ArgumentMatchers.any());
870870
}
871871

872+
@Test
873+
public void shouldNotFeedbackJsonLdKeywords() {
874+
final Metafix metafix = fix(
875+
"map(_else)"
876+
);
877+
878+
metafix.startRecord("1");
879+
metafix.literal("@id", LITERAL_HAWAII);
880+
metafix.endRecord();
881+
882+
Mockito.verify(streamReceiver).literal("@id", LITERAL_HAWAII);
883+
}
884+
872885
@Test
873886
@Disabled("Fix syntax")
874887
public void shouldReplaceVariables() {

0 commit comments

Comments
 (0)