diff --git a/stdlib/ktSrc/dom/Dom.kt b/stdlib/ktSrc/dom/Dom.kt index 6daaaa6bd58..29ac4efb210 100644 --- a/stdlib/ktSrc/dom/Dom.kt +++ b/stdlib/ktSrc/dom/Dom.kt @@ -190,9 +190,9 @@ fun Element.get(selector: String): List { } } -/** Returns the attribute value or null if its not present */ -inline fun Element?.attribute(name: String): String? { - return this?.getAttribute(name) +/** Returns the attribute value or empty string if its not present */ +inline fun Element.attribute(name: String): String { + return this.getAttribute(name) ?: "" } /** Returns the children of the element as a list */ diff --git a/testlib/test/dom/DomBuilderTest.kt b/testlib/test/dom/DomBuilderTest.kt index 8884fc9f940..f61341672bd 100644 --- a/testlib/test/dom/DomBuilderTest.kt +++ b/testlib/test/dom/DomBuilderTest.kt @@ -89,7 +89,7 @@ class DomBuilderTest() : TestSupport() { if (grandChild != null) { println("got element ${grandChild.toXmlString()} with text '${grandChild.text}`") assertEquals("Hello World!", grandChild.text) - assertEquals(" bar tiny", grandChild.attribute("class") ?: "") + assertEquals(" bar tiny", grandChild.attribute("class")) // test the classSet val classSet = grandChild.classSet