소스 검색

LibWeb: Propagate exceptions from setAttribute() in DOMStringMap setter

We were incorrectly assuming that setAttribute() could never fail here,
even when passed an invalid name.

Found by Domato.
Andreas Kling 1 년 전
부모
커밋
093f1dd805

+ 1 - 0
Tests/LibWeb/Text/expected/DOM/DOMStringMap-setter-with-invalid-name.txt

@@ -0,0 +1 @@
+Setting DOMStringMap with an invalid name key throws? true

+ 12 - 0
Tests/LibWeb/Text/input/DOM/DOMStringMap-setter-with-invalid-name.html

@@ -0,0 +1,12 @@
+<script src="../include.js"></script>
+<script>
+    test(() => {
+        let threw = false;
+        try {
+            document.body.dataset["'\uDBF8"] = "foo";
+        } catch {
+            threw = true;
+        }
+        println("Setting DOMStringMap with an invalid name key throws? " + threw);
+    });
+</script>

+ 1 - 1
Userland/Libraries/LibWeb/HTML/DOMStringMap.cpp

@@ -165,7 +165,7 @@ WebIDL::ExceptionOr<void> DOMStringMap::set_value_of_new_named_property(String c
     // FIXME: 4. If name does not match the XML Name production, throw an "InvalidCharacterError" DOMException.
 
     // 5. Set an attribute value for the DOMStringMap's associated element using name and value.
-    MUST(m_associated_element->set_attribute(data_name, value));
+    TRY(m_associated_element->set_attribute(data_name, value));
 
     return {};
 }