Skip to content
New issue

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

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

Already on GitHub? # to your account

Leading and trailing whitespace invalidates CSS colors #2301

Closed
1 task done
haykam821 opened this issue Nov 2, 2023 · 1 comment
Closed
1 task done

Leading and trailing whitespace invalidates CSS colors #2301

haykam821 opened this issue Nov 2, 2023 · 1 comment

Comments

@haykam821
Copy link

Building off of #2300, having whitespace at the start or end of the CSS color used to set a fill style, for example, invalidates the color, which is inconsistent with browser behavior and the specification. (This specification also allows comments to appear, which are also incorrectly parsed here.)

Steps to Reproduce

Compare the results of running the following snippet in a browser and in Node.js with canvas:

const canvas = "document" in globalThis ? document.createElement("canvas") : require("canvas").createCanvas();
const context = canvas.getContext("2d");

const entries = [
	"red",
	" red",
	" red ",
	"#ff0000",
	" #ff0000",
	"#ff0000 "
];

for (const entry of entries) {
	context.fillStyle = entry;
	console.log(context.fillStyle);
}

Environment

  • canvas 2.11.2
  • macOS Sonoma 14.1
@zbjornson
Copy link
Collaborator

Fixed in #2384, will be in the next 3.0.0-rc and final v3.0.0.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants