diff --git a/metafix/src/main/java/org/metafacture/metafix/FixMethod.java b/metafix/src/main/java/org/metafacture/metafix/FixMethod.java index a3f1eaec..42f9f0be 100644 --- a/metafix/src/main/java/org/metafacture/metafix/FixMethod.java +++ b/metafix/src/main/java/org/metafacture/metafix/FixMethod.java @@ -99,7 +99,7 @@ public void apply(final Metafix metafix, final Record record, final List add_field { @Override public void apply(final Metafix metafix, final Record record, final List params, final Map options) { - record.add(params.get(0), new Value(params.get(1))); + record.addNested(params.get(0), new Value(params.get(1))); } }, array { // array-from-hash @@ -111,8 +111,8 @@ public void apply(final Metafix metafix, final Record record, final List record.remove(field); h.forEach((subField, value) -> { - record.add(field, new Value(subField)); - record.add(field, value); + record.addNested(field, new Value(subField)); + record.addNested(field, value); }); }))); } @@ -123,7 +123,7 @@ public void apply(final Metafix metafix, final Record record, final List final String oldName = params.get(0); final String newName = params.get(1); Value.asList(record.get(oldName), a -> a.forEach(newValue -> { - record.add(newName, newValue); + record.addNested(newName, newValue); newValue.updatePathRename(newName); })); } @@ -185,11 +185,11 @@ public void apply(final Metafix metafix, final Record record, final List }); if (!value.asHash().isEmpty()) { - record.add(field, value); + record.addNested(field, value); } else { for (int i = 1; i <= m.groupCount(); i = i + 1) { - record.add(field, new Value(m.group(i))); + record.addNested(field, new Value(m.group(i))); } } } diff --git a/metafix/src/main/java/org/metafacture/metafix/Record.java b/metafix/src/main/java/org/metafacture/metafix/Record.java index 275c9964..655f5785 100644 --- a/metafix/src/main/java/org/metafacture/metafix/Record.java +++ b/metafix/src/main/java/org/metafacture/metafix/Record.java @@ -150,16 +150,14 @@ public void add(final String field, final Value newValue) { super.add(field, newValue); } else { - final FixPath fixPath = new FixPath(field); - if (fixPath.size() > 1) { - fixPath.insertInto(this, InsertMode.APPEND, newValue); - } - else { - put(field, newValue); - } + put(field, newValue); } } + public void addNested(final String field, final Value newValue) { + new FixPath(field).insertInto(this, InsertMode.APPEND, newValue); + } + /** * Sets a field/value pair to this record, replacing * any previous association of the field with a value. diff --git a/metafix/src/test/java/org/metafacture/metafix/MetafixRecordTest.java b/metafix/src/test/java/org/metafacture/metafix/MetafixRecordTest.java index 176b331f..6f783b4d 100644 --- a/metafix/src/test/java/org/metafacture/metafix/MetafixRecordTest.java +++ b/metafix/src/test/java/org/metafacture/metafix/MetafixRecordTest.java @@ -2694,4 +2694,43 @@ public void shouldRenameArrayFieldWithAsterisk() { ); } + @Test + @MetafixToDo("See https://github.com/metafacture/metafacture-fix/pull/170") + public void shouldNotSplitLiteralName() { + MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( + "nothing()" + ), + i -> { + i.startRecord("1"); + i.literal("123. ", "foo"); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().literal("123. ", "foo"); + o.get().endRecord(); + } + ); + } + + @Test + public void shouldNotSplitEntityName() { + MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList( + "nothing()" + ), + i -> { + i.startRecord("1"); + i.startEntity("123. "); + i.endEntity(); + i.endRecord(); + }, + o -> { + o.get().startRecord("1"); + o.get().startEntity("123. "); + o.get().endEntity(); + o.get().endRecord(); + } + ); + } + }