Skip to content

Commit 281a19c

Browse files
committed
Fix an edge case in the BBCode parser
1 parent 3d7adf8 commit 281a19c

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/main/kotlin/me/proxer/app/ui/view/bbcode/prototype/ColorPrototype.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@ object ColorPrototype : BBPrototype {
2121
)
2222

2323
private val availableColorsForRegex = availableColors.joinToString("|") { it.first }
24+
private val colorsForRegex = "(#[A-Fa-f0-9]{6}|#[A-Fa-f0-9]{8}|$availableColorsForRegex)"
2425

25-
override val startRegex = Regex("\\s*color\\s*=\\s*(#[A-Fa-f0-9]{6}|#[A-Fa-f0-9]{8}|$availableColorsForRegex)\\s*",
26-
RegexOption.IGNORE_CASE)
26+
override val startRegex = Regex("\\s*color\\s*=\\s*\"?$colorsForRegex\"?\\s*", RegexOption.IGNORE_CASE)
2727

2828
override val endRegex = Regex("/\\s*color\\s*", RegexOption.IGNORE_CASE)
2929

3030
override fun construct(code: String, parent: BBTree): BBTree {
31-
val value = code.substringAfter("=").trim()
31+
val value = code.substringAfter("=").trim().replace("\"", "")
32+
3233
val color = when (value.startsWith("#")) {
3334
true -> Color.parseColor(value)
3435
false -> availableColors.find { it.first == value }?.second

src/main/kotlin/me/proxer/app/ui/view/bbcode/prototype/SizePrototype.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import me.proxer.app.ui.view.bbcode.tree.SizeTree
88
*/
99
object SizePrototype : BBPrototype {
1010

11-
override val startRegex = Regex("\\s*size\\s*=\\s*[1-6]\\s*", RegexOption.IGNORE_CASE)
11+
override val startRegex = Regex("\\s*size\\s*=\\s*\"?[1-6]\"?\\s*", RegexOption.IGNORE_CASE)
1212
override val endRegex = Regex("/\\s*size\\s*", RegexOption.IGNORE_CASE)
1313

1414
override fun construct(code: String, parent: BBTree): BBTree {
15-
val value = code.substringAfter("=").trim().getOrNull(0)
15+
val value = code.substringAfter("=").trim().replace("\"", "").getOrNull(0)
1616

1717
return when (value) {
1818
'1' -> SizeTree(0.4f, parent)

0 commit comments

Comments
 (0)