From 3c6472dc0089f22080f3a513809164e9f04f9aad Mon Sep 17 00:00:00 2001 From: Tim Ledbetter Date: Sat, 6 Sep 2025 02:20:48 +0100 Subject: [PATCH] LibWeb: Do nothing when calling `CanvasPath.closePath()` with empty path --- Libraries/LibWeb/HTML/Canvas/CanvasPath.cpp | 6 +++++ .../HTML/canvas-close-empty-path-ref.html | 3 +++ .../input/HTML/canvas-close-empty-path.html | 22 +++++++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 Tests/LibWeb/Ref/expected/HTML/canvas-close-empty-path-ref.html create mode 100644 Tests/LibWeb/Ref/input/HTML/canvas-close-empty-path.html diff --git a/Libraries/LibWeb/HTML/Canvas/CanvasPath.cpp b/Libraries/LibWeb/HTML/Canvas/CanvasPath.cpp index 096e8a8bae4..50032d74291 100644 --- a/Libraries/LibWeb/HTML/Canvas/CanvasPath.cpp +++ b/Libraries/LibWeb/HTML/Canvas/CanvasPath.cpp @@ -23,8 +23,14 @@ void CanvasPath::ensure_subpath(float x, float y) m_path.move_to(Gfx::FloatPoint { x, y }); } +// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-closepath void CanvasPath::close_path() { + // The closePath() method, when invoked, must do nothing if the object's path has no subpaths. Otherwise, it must + // mark the last subpath as closed, create a new subpath whose first point is the same as the previous subpath's + // first point, and finally add this new subpath to the path. + if (m_path.is_empty()) + return; m_path.close(); } diff --git a/Tests/LibWeb/Ref/expected/HTML/canvas-close-empty-path-ref.html b/Tests/LibWeb/Ref/expected/HTML/canvas-close-empty-path-ref.html new file mode 100644 index 00000000000..bd0e80ab1a3 --- /dev/null +++ b/Tests/LibWeb/Ref/expected/HTML/canvas-close-empty-path-ref.html @@ -0,0 +1,3 @@ + +
There should be no diagonal line drawn to the canvas
+ diff --git a/Tests/LibWeb/Ref/input/HTML/canvas-close-empty-path.html b/Tests/LibWeb/Ref/input/HTML/canvas-close-empty-path.html new file mode 100644 index 00000000000..e8ca92b01c4 --- /dev/null +++ b/Tests/LibWeb/Ref/input/HTML/canvas-close-empty-path.html @@ -0,0 +1,22 @@ + + +
There should be no diagonal line drawn to the canvas
+ +