From 0c854f9afcd740585782e1a111feb34acbc3a614 Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Thu, 23 Jan 2025 10:47:46 +0100 Subject: [PATCH] LibWeb: Return true if invalid color was provided to an editing command Both Chrome and Firefox return `true` whenever the value string provided is an invalid color or the current color. Spec issue raised: https://github.com/w3c/editing/issues/476 --- Libraries/LibWeb/Editing/Commands.cpp | 10 ++++++---- .../Text/expected/Editing/execCommand-backColor.txt | 1 + .../Text/input/Editing/execCommand-backColor.html | 3 +++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Libraries/LibWeb/Editing/Commands.cpp b/Libraries/LibWeb/Editing/Commands.cpp index 20b2dd46cbe..58e550c24c4 100644 --- a/Libraries/LibWeb/Editing/Commands.cpp +++ b/Libraries/LibWeb/Editing/Commands.cpp @@ -35,9 +35,10 @@ bool command_back_color_action(DOM::Document& document, String const& value) resulting_value = MUST(String::formatted("#{}", resulting_value)); // 2. If value is still not a valid CSS color, or if it is currentColor, return false. + // AD-HOC: No browser does this. They always return true. if (!Color::from_string(resulting_value).has_value()) { - // FIXME: Also return false in case of currentColor. - return false; + // FIXME: Also return true in case of currentColor. + return true; } } @@ -602,9 +603,10 @@ bool command_fore_color_action(DOM::Document& document, String const& value) resulting_value = MUST(String::formatted("#{}", resulting_value)); // 2. If value is still not a valid CSS color, or if it is currentColor, return false. + // AD-HOC: No browser does this. They always return true. if (!Color::from_string(resulting_value).has_value()) { - // FIXME: Also return false in case of currentColor. - return false; + // FIXME: Also return true in case of currentColor. + return true; } } diff --git a/Tests/LibWeb/Text/expected/Editing/execCommand-backColor.txt b/Tests/LibWeb/Text/expected/Editing/execCommand-backColor.txt index 738319e55c5..fd51346af7d 100644 --- a/Tests/LibWeb/Text/expected/Editing/execCommand-backColor.txt +++ b/Tests/LibWeb/Text/expected/Editing/execCommand-backColor.txt @@ -1,2 +1,3 @@ Div contents: "foobar" Div contents: "foobar" +Invalid color result: true diff --git a/Tests/LibWeb/Text/input/Editing/execCommand-backColor.html b/Tests/LibWeb/Text/input/Editing/execCommand-backColor.html index 7ec26de2ec5..d485ec35c9d 100644 --- a/Tests/LibWeb/Text/input/Editing/execCommand-backColor.html +++ b/Tests/LibWeb/Text/input/Editing/execCommand-backColor.html @@ -18,5 +18,8 @@ range.setEnd(divElm.childNodes[1], 3); document.execCommand('hiliteColor', false, 'red'); println(`Div contents: "${divElm.innerHTML}"`); + + // Invalid color + println(`Invalid color result: ${document.execCommand('backColor', false, '%*&')}`); });