Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Got a TypeError after converting xliff12 to json with empty groups #53

Closed
WindowGenerator opened this issue Feb 28, 2022 · 1 comment
Closed

Comments

@WindowGenerator
Copy link

🐛 Bug Report

Got a TypeError after converting xliff12 to json with empty groups

To Reproduce

  1. Сonvert xliff12 with empty group to json
  2. Got TypeError:
TypeError: Cannot read property 'filter' of undefined
    at /.../node_modules/xliff/cjs/xliff12ToJs.js:67:35
    at Array.reduce (<anonymous>)
    at createUnits (/...node_modules/xliff/cjs/xliff12ToJs.js:65:24)
    at /.../node_modules/xliff/cjs/xliff12ToJs.js:57:28
    at Array.reduce (<anonymous>)
    at xliff12ToJsClb (/.../node_modules/xliff/cjs/xliff12ToJs.js:48:41)
    at /.../node_modules/xliff/cjs/xliff12ToJs.js:121:14
    at new Promise (<anonymous>)
    at Object.xliff12ToJs (/.../node_modules/xliff/cjs/xliff12ToJs.js:120:12)
    at readXlf (/.../src/locale/scripts/failure_example.js:15:24)

Artifact:

<xliff xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 http://docs.oasis-open.org/xliff/v1.2/os/xliff-core-1.2-strict.xsd" xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
   <file original="namespace1" datatype="plaintext" source-language="en-US" target-language="ru-RU">
        <body>
            <trans-unit id="standalone">
                <source>Source</source>
                <target>Target</target>
            </trans-unit>
            <group id="example-empty-group"></group>
        </body>
    </file>
</xliff>

Code to reproduce:

const xliff = require('xliff');

async function readXlf() {
    const rawXliff = `<xliff xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:oasis:names:tc:xliff:document:1.2 http://docs.oasis-open.org/xliff/v1.2/os/xliff-core-1.2-strict.xsd" xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
        <file original="namespace1" datatype="plaintext" source-language="en-US" target-language="ru-RU">
            <body>
                <trans-unit id="standalone">
                    <source>Source</source>
                    <target>Target</target>
                </trans-unit>
                <group id="example-empty-group"></group>
            </body>
            </file>
        </xliff>`;
    return await xliff.xliff12ToJs(rawXliff);
}


readXlf();

Expected behavior

Get correct error or ignore empty groups

Your Environment

  • runtime version: i.e. node v10.19.0
  • xliff version: 6.0.1
  • os: Linux Manjaro
@adrai adrai closed this as completed in 1b47d87 Feb 28, 2022
@adrai
Copy link
Contributor

adrai commented Feb 28, 2022

v6.0.2 will not throw anymore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants