-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Color-stop matching fails with TypeError due to faulty regexp #469
Comments
A pull request with the fix and tests to support it would be excellent! |
I'll try to take a look this weekend. Note to self: |
Regarding implementing border-style inset, there is a need to get a common parsing for colors as well, since it needs to darken/lighten colors by a specific percentage. With this gradient fix, if there is a need for parsing colors into a common format, it could be useful with the border-style: inset as well. For example, if any color (hex, rgb, rgba, hls, hlsa, predefined name such as 'red', 'green' etc.) could be parsed into Color object with r, g, b and a values defined, it would make it significantly easier to implement the border inset as well. |
Agreed that a common color parsing/representation can and should be reused. I'll keep it in mind and probably have questions. |
Didn't get a chance to look at this over the weekend, will possibly/hopefully have time tomorrow. |
Any update on this? |
Er, sorry, not yet. :/ Been swamped and had limited computing resources, though I did set up some tests locally (haven't implemented anything yet). |
I've added basic color parsing (named, rgb, rgba, hex3 and hex6 so far) and changed all uses of color to use those. The gradient regexps haven't been updated yet. See 313c227 |
Nice! I'll take a look this weekend and see about updating those regexps. |
For review - TESTS COMING SOON. Also fixes some CSS2 linear gradients (Firefox). Ref niklasvh#469.
@niklasvh Can you take a look at the commit I just made on my branch (359ee8b) and let me know what you think? I'll remove my superfluous comments and will add tests for color names soon, but can you please also take a look at the other change? I corrected direction parsing for Firefox, so certain linear gradients that didn't render correctly before should now work. You can see the manual test I just temporarily put in |
Hmm, hold that thought, I may have done something weird, squares on my home machine are mostly black now.. |
Ah, nope, looks like 4985279 is the problem commit, my stuff looks ok. 😅 |
What happens if the percentage is something else than 100% or 0%? |
As of right now it doesn't support arbitrary percentages (leaves them as the default 50%), but I can add that easily enough. (Update: added support for arbitrary percentages: 6af1874.) What I'm not as sure about are non-percentage lengths, which can be in |
absolute lengths should be easy to implement, but I think px should be enough to begin with. |
- Updates CSS color stop regular expression to accept color names - Handles arbitrary gradient direction percentages - Handles certain CSS2 linear gradients (fixes Firefox). Ref niklasvh#469. TODO: - add support for px (see CanvasRenderer.prototype.renderBackgroundGradient) - update regexps to support floating point numbers (see niklasvh#505) - add tests
- Updates CSS color stop regular expression to accept color names - Handles arbitrary gradient direction percentages - Handles certain CSS2 linear gradients (fixes Firefox). Ref niklasvh#469. TODO: - add support for px (see CanvasRenderer.prototype.renderBackgroundGradient) - update regexps to support floating point numbers (see niklasvh#505) - add tests
- Updates CSS color stop regular expression to accept color names - Handles arbitrary gradient direction percentages - Handles certain CSS2 linear gradients (fixes Firefox). Ref niklasvh#469. TODO: - add support for px (see CanvasRenderer.prototype.renderBackgroundGradient) - update regexps to support floating point numbers (see niklasvh#505) - add tests
Also: - Cleans up color stop and linear gradient regular expressions. - Handles percentage-based linear gradient positions (fixes Firefox). Fixes niklasvh#469.
@niklasvh I've just gotten some more time to look at and work on this. Can you take a look at my I should note that, although the regexps can parse pixel lengths (both in gradient start positions and color stop positions), there's still no support for correctly rendering them. I think the cleanest way to add support for absolute lengths would be to include bounds information with the |
Also: - Cleans up color stop and linear gradient regular expressions. - Handles percentage-based linear gradient positions (fixes Firefox). Fixes niklasvh#469.
Thanks! Will have a closer look at this shortly and get back to you with any feedback I might have |
Any progress on this? It's still needed! |
I'm ready to make a pull request if @niklasvh can give the approach I used on my branch a thumbs-up.. |
👍 I just ran into this:
|
Hey @niklasvh! Thanks for fixing #526. Did you ever get a chance to look at my |
@usmonster No, sorry I missed that. One potential problem I was thinking while doing that fix is that if the browser decides not to convert named colors such as Any ideas how the named colors could be handled? |
@niklasvh, The lookup and normalization that's already done by the Additionally, I've fixed up the regular expressions used for parsing colors and linear gradients to make them more robust, correct, and performant, so I don't think named colors should be an issue. What do you think? |
@usmonster You are right, I was referring to master...usmonster:fix-firefox-gradients#diff-48b5afb6985c457b9f79fcca1cfb499dR21 which I now noticed does take into account named colors, so no problem there. Looks good otherwise, would you mind rebasing and putting up a pull request? |
No problem! I'll try to take a look in the next couple of days--I kind of missed my weekend window. :/ |
Also: - Cleans up color stop and linear gradient regular expressions. - Handles percentage-based linear gradient positions (fixes Firefox). Fixes niklasvh#469.
Also: - Cleans up color stop and linear gradient regular expressions. - Handles percentage-based linear gradient positions (fixes Firefox). Fixes niklasvh#469.
Also: - Cleans up color stop and linear gradient regular expressions. - Handles percentage-based linear gradient positions (fixes Firefox). Fixes niklasvh#469.
I received "TypeError: colorStopMatch is null" at html2canvas.js:1454:13 in FireFox. In Chrome it working. |
Hi @Observer999! This issue is closed. Please search for a similar open issue or create a new issue with a link to a page that reproduces the issue you're having. (Please also specify there which version of Firefox you've tested in.) I can imagine it might have something to do with the TODOs in the code.. Thanks! |
@usmonster @niklasvh Hello guys I know this issue is closed but I am using the latest version of html2canvas and I am getting the same error in Chrome latest version but in Firefox it is working. html2canvas.js:formatted:1377 Uncaught (in promise) TypeError: Cannot read property '1' of null |
Also: - Cleans up color stop and linear gradient regular expressions. - Handles percentage-based linear gradient positions (fixes Firefox). Fixes niklasvh/html2canvas#469.
I'm seeing a
TypeError
when using color keywords (e.g.transparent
, as opposed torgb()
values) since matching against the "step" regex inLinearGradientContainer
will always returnnull
in that case (see this line).Can you please update the regexp to work as expected with both
[a-z]+
color keywords as well as thergb()
/rgba()
functional notation? Or would you be open to a pull request that does just that? (I can even addhsl()
/hsla()
support to the regexp, if you want...) Thanks!The text was updated successfully, but these errors were encountered: