Skip to content

Commit

Permalink
Fix an edge case in the BBCode parser
Browse files Browse the repository at this point in the history
  • Loading branch information
rubengees committed Dec 13, 2017
1 parent 3d7adf8 commit 281a19c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ object ColorPrototype : BBPrototype {
)

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

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

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

override fun construct(code: String, parent: BBTree): BBTree {
val value = code.substringAfter("=").trim()
val value = code.substringAfter("=").trim().replace("\"", "")

val color = when (value.startsWith("#")) {
true -> Color.parseColor(value)
false -> availableColors.find { it.first == value }?.second
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import me.proxer.app.ui.view.bbcode.tree.SizeTree
*/
object SizePrototype : BBPrototype {

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

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

return when (value) {
'1' -> SizeTree(0.4f, parent)
Expand Down

0 comments on commit 281a19c

Please sign in to comment.