Fixes #1084. Opengraph parser fails when value-less properties are present.

This commit is contained in:
Vitor Pamplona 2024-09-16 11:23:41 -04:00
parent 428ed464af
commit 28da06ef01
2 changed files with 33 additions and 1 deletions

View File

@ -78,4 +78,29 @@ class MetaTagsParserTest {
}
}
}
@Test
fun testParseWithAdditionalTags() {
val input =
"""<html>
| <head>
| <meta data-preact-helmet property="og:title" content="Uma conversa com Antonio Vargas">
| </head>
|</html>
""".trimMargin()
val exp =
listOf(
listOf("property" to "og:title", "content" to "Uma conversa com Antonio Vargas"),
)
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))
}
}
}
}

View File

@ -248,7 +248,14 @@ object MetaTagsParser {
}
c.isWhitespace() -> {}
else -> return null
else -> {
// if it is expecting = but gets another name, starts another property
runCatching { attrs.add(Pair(input.slice(nameBegin..<nameEnd), "")) }
nameBegin = i
state = State.NAME
}
}
}