Repository navigation
throw errors when invalid values passed to dash(...) - #969
Conversation
|
@danthegoodman feedback appreciated 😄 |
danthegoodman
left a comment
There was a problem hiding this comment.
Thanks for the PR! 😁
| return this.addContent(`[${length}] ${number(phase)} d`); | ||
| } else { | ||
| if (!Array.isArray(length) && !Number.isInteger(length) || length === 0) { | ||
| throw new Error(`dash(${length}) invalid, must be number greater than zero`); |
There was a problem hiding this comment.
!Array.isArray(length)has already been checked and will always return true. I think it should be omitted here.- The length doesn't have to be an integer. The PDF spec allows floating point numbers.
Number.isFinite(length)should get you your null check while also covering cases likeNaNand strings and infinities. - Your check is only for zero. You should also check for negative numbers.
There was a problem hiding this comment.
Agreed, nice catches. I went ahead and consolidated the parallel paths in the if and else - seems cleaner now.
| return this; | ||
| } | ||
| if (Array.isArray(length)) { | ||
| const hasZeros = length.filter(x => x === 0).length > 0; |
There was a problem hiding this comment.
- Using either the
everyorsomefunction here will be a little more efficient, since they can short-circuit and doesn't build up an intermediate array. - Like the non-array check, this check should reject negative numbers,
NaN, nulls and other invalid values.
|
@danthegoodman I think it's ready for another look. |
danthegoodman
left a comment
There was a problem hiding this comment.
Nice!
@blikblum / @devongovett I think this is good to go!
|
I'm afraid this will break rendering since does not handle space option. Will do some tests. |
|
@blikblum You're right. I missed that in my second review. Good catch. |
|
I'll get it squared in a couple days unless someone beats me to it.
(misspelled from my mobile phone)
…On Fri, May 3, 2019, 10:51 PM Danny Kirchmeier ***@***.***> wrote:
@blikblum <https://github.com/blikblum> You're right. I missed that in my
second review. Good catch.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#969 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAMIYNA3WAOIOWHVIGHW3J3PTUB5FANCNFSM4HKUFARA>
.
|
|
I added dash unit tests to ensure no regressions are made with f486d11 You should rebase and add the validation tests in |
035dd2f to
fd29fe2
Compare
|
@blikblum thanks for those unit tests for I moved the new tests to |
Co-Authored-By: floyd-may <floyd.may@gmail.com>
|
@blikblum one more look please? |
|
Many thanks |
|
Any guidance on when this fix will be available in a published release? |
In PDFKit >=0.10.0, calling dash() with any 0s in the dash array/length will throw an error. For more info see foliojs/pdfkit#1060 foliojs/pdfkit#949 foliojs/pdfkit#969 A number of SVG editors, I believe including inkscape, will happily generate `stroke-dasharray` attributes with 0s in them, and then running them through SVG-to-PDFKit will cause the conversion to fail completely. So, this commit does a bunch of math to rewrite dash arrays containing 0s to eliminate the zeros, but still achieve the same result. This commit also updates the version of PDFKit the examples use to the latest (0.13.0) and adds a test that exercises a bunch of `stroke-dasharray` scenarios with 0s in them.
In PDFKit >=0.10.0, calling dash() with any 0s in the dash array/length will throw an error. For more info see foliojs/pdfkit#1060 foliojs/pdfkit#949 foliojs/pdfkit#969 A number of SVG editors, I believe including inkscape, will happily generate `stroke-dasharray` attributes with 0s in them, and then running them through SVG-to-PDFKit will cause the conversion to fail completely. So, this commit does a bunch of math to rewrite dash arrays containing 0s to eliminate the zeros, but still achieve the same result. This commit also updates the version of PDFKit the examples use to the latest (0.13.0) and adds a test that exercises a bunch of `stroke-dasharray` scenarios with 0s in them.
In PDFKit >=0.10.0, calling dash() with any 0s in the dash array/length will throw an error. For more info see foliojs/pdfkit#1060 foliojs/pdfkit#949 foliojs/pdfkit#969 A number of SVG editors, I believe including inkscape, will happily generate `stroke-dasharray` attributes with 0s in them, and then running them through SVG-to-PDFKit will cause the conversion to fail completely. So, this commit does a bunch of math to rewrite dash arrays containing 0s to eliminate the zeros, but still achieve the same result. This commit also updates the version of PDFKit the examples use to the latest (0.13.0) and adds a test that exercises a bunch of `stroke-dasharray` scenarios with 0s in them.
In PDFKit >=0.10.0, calling dash() with any 0s in the dash array/length will throw an error. For more info see foliojs/pdfkit#1060 foliojs/pdfkit#949 foliojs/pdfkit#969 A number of SVG editors, I believe including inkscape, will happily generate `stroke-dasharray` attributes with 0s in them, and then running them through SVG-to-PDFKit will cause the conversion to fail completely. So, this commit does a bunch of math to rewrite dash arrays containing 0s to eliminate the zeros, but still achieve the same result. This commit also updates the version of PDFKit the examples use to the latest (0.13.0) and adds a test that exercises a bunch of `stroke-dasharray` scenarios with 0s in them.
In PDFKit >=0.10.0, calling dash() with any 0s in the dash array/length will throw an error. For more info see foliojs/pdfkit#1060 foliojs/pdfkit#949 foliojs/pdfkit#969 A number of SVG editors, I believe including inkscape, will happily generate `stroke-dasharray` attributes with 0s in them, and then running them through SVG-to-PDFKit will cause the conversion to fail completely. So, this commit does a bunch of math to rewrite dash arrays containing 0s to eliminate the zeros, but still achieve the same result. This commit also updates the version of PDFKit the examples use to the latest (0.13.0) and adds a test that exercises a bunch of `stroke-dasharray` scenarios with 0s in them.
The dash(...) function now throws errors when passed invalid values
Fixes #949. Current behavior is that
dash(...)accepts values such as0for length, which breaks rendering in some viewers. There is a demo in the linked issue of the impact of the problem.Checklist: