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

Empty string shows error: unsupported number: -Infinity #1851

Closed
tobwithu opened this issue Jun 2, 2022 · 2 comments · Fixed by #1858
Closed

Empty string shows error: unsupported number: -Infinity #1851

tobwithu opened this issue Jun 2, 2022 · 2 comments · Fixed by #1858
Labels

Comments

@tobwithu
Copy link

tobwithu commented Jun 2, 2022

Thank you for this great tool.
However, I found a bug.
Empty string shows error: unsupported number: -Infinity

Code

<Document>
        <Page>
            <View style={{alignItems: 'center'}}>
                <Text style={{textAlign: "center"}}>{""}</Text>
            </View>
        </Page>
</Document>

Result

Error: unsupported number: -Infinity
    at Function.number (pdfkit.browser.es.js:273:1)
    at pdfkit.browser.es.js:1866:1
    at Array.map (<anonymous>)
    at PDFDocument.transform (pdfkit.browser.es.js:1865:1)
    at PDFDocument.translate (pdfkit.browser.es.js:1871:1)
    at renderText (renderText.js:233:1)
    at _curryN.js:34:1
    at _arity.js:10:1
    at cond.js:42:1
    at _arity.js:10:1
    at _pipe.js:3:1
    at _pipe.js:3:1
    at _pipe.js:3:1
    at _pipe.js:3:1
    at _pipe.js:3:1
    at _pipe.js:3:1
    at _arity.js:10:1
    at renderNode.js:80:1
    at Array.forEach (<anonymous>)
    at renderNode.js:72:1
    at when (when.js:32:1)
    at _curry3.js:28:1
    at f1 (_curry1.js:16:1)
    at _pipe.js:3:1
    at _pipe.js:3:1
    at _pipe.js:3:1
    at _pipe.js:3:1
    at _arity.js:10:1
    at renderNode.js:80:1
    at Array.forEach (<anonymous>)
    at renderNode.js:72:1
    at when (when.js:32:1)
    at _curry3.js:28:1
    at f1 (_curry1.js:16:1)
    at _pipe.js:3:1
    at _pipe.js:3:1
    at _pipe.js:3:1
    at _pipe.js:3:1
    at _arity.js:10:1
    at renderNode.js:80:1
    at Array.forEach (<anonymous>)
    at index.js:15:1
    at render (index.js:21:1)
    at _callee$ (index.js:35:1)
    at tryCatch (regeneratorRuntime.js:86:1)
    at Generator._invoke (regeneratorRuntime.js:66:1)
    at Generator.next (regeneratorRuntime.js:117:1)
    at asyncGeneratorStep (asyncToGenerator.js:3:1)
    at _next (asyncToGenerator.js:25:1)

Desktop (please complete the following information):

  • OS: [MacOS]
  • Browser [chrome]
  • React-pdf version [e.g. v2.1.2]
@modosc
Copy link

modosc commented Jun 3, 2022

i think the issue is here:

if (!node.lines) return -1;
return Math.max(...node.lines.map(line => advanceWidth(line)));

i think if (!node.lines) should be if (!node.lines || node.lines.length === 0) because otherwise when node.lines = [] Math.max() is called without any args and returns -Infinity

@diegomura
Copy link
Owner

Thanks! Fixed. Weird, I'm also able to replicate it in older versions. Seems it's been here for awhile? Maybe I tested it wrong

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

Successfully merging a pull request may close this issue.

3 participants