Skip to content

Commit dedbbb7

Browse files
committed
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: w3c/editing#476
1 parent 94a8b63 commit dedbbb7

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

Libraries/LibWeb/Editing/Commands.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ bool command_back_color_action(DOM::Document& document, String const& value)
3535
resulting_value = MUST(String::formatted("#{}", resulting_value));
3636

3737
// 2. If value is still not a valid CSS color, or if it is currentColor, return false.
38+
// AD-HOC: No browser does this. They always return true.
3839
if (!Color::from_string(resulting_value).has_value()) {
39-
// FIXME: Also return false in case of currentColor.
40-
return false;
40+
// FIXME: Also return true in case of currentColor.
41+
return true;
4142
}
4243
}
4344

@@ -602,9 +603,10 @@ bool command_fore_color_action(DOM::Document& document, String const& value)
602603
resulting_value = MUST(String::formatted("#{}", resulting_value));
603604

604605
// 2. If value is still not a valid CSS color, or if it is currentColor, return false.
606+
// AD-HOC: No browser does this. They always return true.
605607
if (!Color::from_string(resulting_value).has_value()) {
606-
// FIXME: Also return false in case of currentColor.
607-
return false;
608+
// FIXME: Also return true in case of currentColor.
609+
return true;
608610
}
609611
}
610612

Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
Div contents: "<span style="background-color: rgb(0, 0, 255);">foo</span>bar"
22
Div contents: "<span style="background-color: rgb(0, 0, 255);">foo</span><span style="background-color: red;">bar</span>"
3+
Invalid color result: true

Tests/LibWeb/Text/input/Editing/execCommand-backColor.html

+3
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,8 @@
1818
range.setEnd(divElm.childNodes[1], 3);
1919
document.execCommand('hiliteColor', false, 'red');
2020
println(`Div contents: "${divElm.innerHTML}"`);
21+
22+
// Invalid color
23+
println(`Invalid color result: ${document.execCommand('backColor', false, '%*&')}`);
2124
});
2225
</script>

0 commit comments

Comments
 (0)