Skip to content

Commit

Permalink
Add failing test
Browse files Browse the repository at this point in the history
Cover case with property name with no value
  • Loading branch information
davotoula committed Sep 16, 2024
1 parent 428ed46 commit aa49104
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,36 @@ class MetaTagsParserTest {
}
}
}

@Test
fun testParseExtraAttributeInMetaTag() {
val input =
"""<html>
| <head>
| <meta data-preact-helmet property="og:title" content="What are your most treasured cookbooks?">
| <meta property="og:description" content='description'>
| <meta data-preact-helmet property="second" data-preact-helmet content="What are your most">
| </head>
| <body>
| <meta name="ignore meta tags in body">
| </body>
|</html>
""".trimMargin()

val exp =
listOf(
listOf("property" to "og:title", "content" to "What are your most treasured cookbooks?"),
listOf("property" to "og:description", "content" to "description"),
listOf("property" to "second", "content" to "What are your most"),
)

val metaTags = MetaTagsParser.parse(input).toList()
println(metaTags)
assertEquals(exp.size, metaTags.size)
metaTags.zip(exp).forEach { (meta, expAttrs) ->
expAttrs.forEach { (name, expValue) ->
assertEquals(expValue, meta.attr(name))
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,12 @@ object MetaTagsParser {
}

c.isWhitespace() -> {}
c.isLetter() -> {
// If we find a letter instead of EQ we probably passed a property with no value
// so lets reset to state NAME and continue
nameBegin = i
state = State.NAME
}
else -> return null
}
}
Expand Down

0 comments on commit aa49104

Please sign in to comment.