Skip to content

Commit

Permalink
"href" can now contain an empty value
Browse files Browse the repository at this point in the history
- which is valid html, but was optimized out by this library
  • Loading branch information
RandomHashTags committed Oct 23, 2024
1 parent a4d9ea5 commit 0979f76
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/HTMLKitMacros/HTMLElement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ private extension HTMLElement {
switch returnType {
case .boolean: return string.elementsEqual("true") ? "" : nil
case .string, .enumCase:
if returnType == .string && string.isEmpty {
if returnType == .string && string.isEmpty && key != "href" {
return nil
}
string.escapeHTML(escapeAttributes: true)
Expand Down
14 changes: 14 additions & 0 deletions Tests/HTMLKitTests/HTMLKitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,20 @@ extension HTMLKitTests {
string = #html(xmlns: "test")
#expect(string == "<!DOCTYPE html><html xmlns=\"test\"></html>")
}
@Test func element_a() {
var string:String = #a("Test")
#expect(string == "<a>Test</a>")

string = #a(href: "test", "Test")
#expect(string == "<a href=\"test\">Test</a>")

string = #a(href: "", "Test")
#expect(string == "<a href>Test</a>")

let test:String = "test"
string = #a(href: "\(test)", "Test")
#expect(string == "<a href=\"test\">Test</a>")
}
@Test func element_area() {
var string:StaticString = #area(coords: [1, 2, 3])
#expect(string == "<area coords=\"1,2,3\">")
Expand Down

0 comments on commit 0979f76

Please sign in to comment.