From f6df4d7a7e4f828dc67cd735737b38f6c9145da8 Mon Sep 17 00:00:00 2001 From: AdriAt360 Date: Mon, 26 Feb 2024 17:36:20 +0100 Subject: [PATCH 1/3] tests: add tests for the failing case --- test/fixtures/example.json | 4 ++++ test/fixtures/example.xliff | 6 ++++++ test/fixtures/example12.xliff | 4 ++++ test/fixtures/example12_output_note.xliff | 4 ++++ test/fixtures/example_compact.xliff | 2 +- test/fixtures/example_compact12.xliff | 2 +- test/fixtures/example_output_note.json | 4 ++++ test/fixtures/example_output_note.xliff | 6 ++++++ test/fixtures/example_source.json | 3 ++- test/fixtures/example_source_attr12.xliff | 4 ++++ test/fixtures/example_target.json | 3 ++- 11 files changed, 38 insertions(+), 4 deletions(-) diff --git a/test/fixtures/example.json b/test/fixtures/example.json index 3c9ac15..a206e5b 100644 --- a/test/fixtures/example.json +++ b/test/fixtures/example.json @@ -16,6 +16,10 @@ "to ' \"esc & e": { "source": "special chars", "target": "spezielle Charakter" + }, + "keyWithEmptySource": { + "source": "", + "target": "Anything" } } }, diff --git a/test/fixtures/example.xliff b/test/fixtures/example.xliff index 5b69151..59e4fad 100644 --- a/test/fixtures/example.xliff +++ b/test/fixtures/example.xliff @@ -24,5 +24,11 @@ spezielle Charakter + + + + Anything + + diff --git a/test/fixtures/example12.xliff b/test/fixtures/example12.xliff index 30255d6..efc9e6a 100644 --- a/test/fixtures/example12.xliff +++ b/test/fixtures/example12.xliff @@ -17,6 +17,10 @@ special chars spezielle Charakter + + + Anything + diff --git a/test/fixtures/example12_output_note.xliff b/test/fixtures/example12_output_note.xliff index edf9239..0a021be 100644 --- a/test/fixtures/example12_output_note.xliff +++ b/test/fixtures/example12_output_note.xliff @@ -20,6 +20,10 @@ spezielle Charakter special chars note + + + Anything + diff --git a/test/fixtures/example_compact.xliff b/test/fixtures/example_compact.xliff index ecd65dd..3f90416 100644 --- a/test/fixtures/example_compact.xliff +++ b/test/fixtures/example_compact.xliff @@ -1 +1 @@ -HelloHalloAn application to manipulate and process XLIFF documentsEine Applikation um XLIFF Dokumente zu manipulieren und verarbeitenXLIFF Data ManagerXLIFF Daten Managerspecial charsspezielle Charakter \ No newline at end of file +HelloHalloAn application to manipulate and process XLIFF documentsEine Applikation um XLIFF Dokumente zu manipulieren und verarbeitenXLIFF Data ManagerXLIFF Daten Managerspecial charsspezielle CharakterAnything diff --git a/test/fixtures/example_compact12.xliff b/test/fixtures/example_compact12.xliff index fe8a644..0eb967d 100644 --- a/test/fixtures/example_compact12.xliff +++ b/test/fixtures/example_compact12.xliff @@ -1 +1 @@ -HelloHalloAn application to manipulate and process XLIFF documentsEine Applikation um XLIFF Dokumente zu manipulieren und verarbeitenXLIFF Data ManagerXLIFF Daten Managerspecial charsspezielle Charakter \ No newline at end of file +HelloHalloAn application to manipulate and process XLIFF documentsEine Applikation um XLIFF Dokumente zu manipulieren und verarbeitenXLIFF Data ManagerXLIFF Daten Managerspecial charsspezielle CharakterAnything diff --git a/test/fixtures/example_output_note.json b/test/fixtures/example_output_note.json index 433ed46..63ccb61 100644 --- a/test/fixtures/example_output_note.json +++ b/test/fixtures/example_output_note.json @@ -19,6 +19,10 @@ "note": "special chars note", "source": "special chars", "target": "spezielle Charakter" + }, + "keyWithEmptySource": { + "source": "", + "target": "Anything" } } }, diff --git a/test/fixtures/example_output_note.xliff b/test/fixtures/example_output_note.xliff index 42e2850..4d34406 100644 --- a/test/fixtures/example_output_note.xliff +++ b/test/fixtures/example_output_note.xliff @@ -33,5 +33,11 @@ spezielle Charakter + + + + Anything + + diff --git a/test/fixtures/example_source.json b/test/fixtures/example_source.json index 7cb352c..aaf01fa 100644 --- a/test/fixtures/example_source.json +++ b/test/fixtures/example_source.json @@ -2,5 +2,6 @@ "key1": "Hello", "key2": "An application to manipulate and process XLIFF documents", "key.nested": "XLIFF Data Manager", - "to ' \"esc & e": "special chars" + "to ' \"esc & e": "special chars", + "keyWithEmptySource": "" } diff --git a/test/fixtures/example_source_attr12.xliff b/test/fixtures/example_source_attr12.xliff index bc06bf8..f341aa3 100644 --- a/test/fixtures/example_source_attr12.xliff +++ b/test/fixtures/example_source_attr12.xliff @@ -17,6 +17,10 @@ special chars spezielle Charakter + + + Anything + diff --git a/test/fixtures/example_target.json b/test/fixtures/example_target.json index 0bda32e..f9cdffb 100644 --- a/test/fixtures/example_target.json +++ b/test/fixtures/example_target.json @@ -2,5 +2,6 @@ "key1": "Hallo", "key2": "Eine Applikation um XLIFF Dokumente zu manipulieren und verarbeiten", "key.nested": "XLIFF Daten Manager", - "to ' \"esc & e": "spezielle Charakter" + "to ' \"esc & e": "spezielle Charakter", + "keyWithEmptySource": "Anything" } From 53e2b7c5205f8aa14bfa4d3692382009750b56ee Mon Sep 17 00:00:00 2001 From: AdriAt360 Date: Mon, 26 Feb 2024 17:41:05 +0100 Subject: [PATCH 2/3] fix: add a source element when the source is an empty string --- lib/js2xliff.js | 2 +- lib/jsToXliff12.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/js2xliff.js b/lib/js2xliff.js index 7382eb4..1e116fa 100644 --- a/lib/js2xliff.js +++ b/lib/js2xliff.js @@ -75,7 +75,7 @@ function createGroupUnitTag (id, group) { function createUnitTag (id, unit) { const segment = makeElement('segment', null, true) if (!unit.source && unit.target) unit.source = '' - if (unit.source) segment.elements.push(makeElement('source', null, makeValue(unit.source, ElementTypes2))) + if (unit.source !== undefined) segment.elements.push(makeElement('source', null, makeValue(unit.source, ElementTypes2))) if (unit.target !== undefined) segment.elements.push(makeElement('target', null, makeValue(unit.target, ElementTypes2))) const subEle = [segment] if ('note' in unit) { diff --git a/lib/jsToXliff12.js b/lib/jsToXliff12.js index 86ef564..13372e5 100644 --- a/lib/jsToXliff12.js +++ b/lib/jsToXliff12.js @@ -75,7 +75,7 @@ function createTransUnitTag (key, resource, obj, options) { } } if (!resource.source && resource.target) resource.source = '' - if (resource.source) u.elements.push(makeElement('source', sourceAttributes, makeValue(resource.source, ElementTypes12))) + if (resource.source != null) u.elements.push(makeElement('source', sourceAttributes, makeValue(resource.source, ElementTypes12))) if (resource.target != null) { let targetAttributes = null if (options.xmlLangAttr && obj.targetLanguage) { From 7a820338ed129d778d87887123bf6e880a3ed7da Mon Sep 17 00:00:00 2001 From: AdriAt360 Date: Mon, 26 Feb 2024 17:41:56 +0100 Subject: [PATCH 3/3] tests: fix test fixtures having invalid format these were broken since the fix --- test/fixtures/example12_diff.xliff | 4 ++++ test/fixtures/example_diff.json | 4 ++++ test/fixtures/example_diff.xliff | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/test/fixtures/example12_diff.xliff b/test/fixtures/example12_diff.xliff index aa267af..bb3bac8 100644 --- a/test/fixtures/example12_diff.xliff +++ b/test/fixtures/example12_diff.xliff @@ -17,15 +17,19 @@ other (AR) + zero (AR) + two (AR) + few (AR) + many (AR) diff --git a/test/fixtures/example_diff.json b/test/fixtures/example_diff.json index 6eb440b..a1133b9 100644 --- a/test/fixtures/example_diff.json +++ b/test/fixtures/example_diff.json @@ -17,15 +17,19 @@ "target": "other (AR)" }, "key2_zero": { + "source": "", "target": "zero (AR)" }, "key2_two": { + "source": "", "target": "two (AR)" }, "key2_few": { + "source": "", "target": "few (AR)" }, "key2_many": { + "source": "", "target": "many (AR)" } } diff --git a/test/fixtures/example_diff.xliff b/test/fixtures/example_diff.xliff index 7ab8b58..4dbc242 100644 --- a/test/fixtures/example_diff.xliff +++ b/test/fixtures/example_diff.xliff @@ -25,21 +25,25 @@ + zero (AR) + two (AR) + few (AR) + many (AR)