[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-taler-android] branch master updated: [wallet] accept but strip m
From: |
gnunet |
Subject: |
[taler-taler-android] branch master updated: [wallet] accept but strip markup in ToS markdown headings |
Date: |
Thu, 30 Apr 2020 20:48:45 +0200 |
This is an automated email from the git hooks/post-receive script.
torsten-grote pushed a commit to branch master
in repository taler-android.
The following commit(s) were added to refs/heads/master by this push:
new 724f9fa [wallet] accept but strip markup in ToS markdown headings
724f9fa is described below
commit 724f9fa491638ae7fcfed07eefa376bacd34d29f
Author: Torsten Grote <address@hidden>
AuthorDate: Thu Apr 30 15:48:01 2020 -0300
[wallet] accept but strip markup in ToS markdown headings
---
.idea/dictionaries/user.xml | 3 ++-
.../java/net/taler/wallet/withdraw/TosSection.kt | 26 +++++++++++++++-------
2 files changed, 20 insertions(+), 9 deletions(-)
diff --git a/.idea/dictionaries/user.xml b/.idea/dictionaries/user.xml
index 4693d75..a29450d 100644
--- a/.idea/dictionaries/user.xml
+++ b/.idea/dictionaries/user.xml
@@ -5,10 +5,11 @@
<w>aiddescription</w>
<w>akono</w>
<w>apdu</w>
+ <w>markwon</w>
<w>servicedesc</w>
<w>snackbar</w>
<w>taler</w>
<w>testkudos</w>
</words>
</dictionary>
-</component>
+</component>
\ No newline at end of file
diff --git a/wallet/src/main/java/net/taler/wallet/withdraw/TosSection.kt
b/wallet/src/main/java/net/taler/wallet/withdraw/TosSection.kt
index 72a9e34..b27de42 100644
--- a/wallet/src/main/java/net/taler/wallet/withdraw/TosSection.kt
+++ b/wallet/src/main/java/net/taler/wallet/withdraw/TosSection.kt
@@ -17,6 +17,7 @@
package net.taler.wallet.withdraw
import io.noties.markwon.Markwon
+import org.commonmark.node.Code
import org.commonmark.node.Document
import org.commonmark.node.Heading
import org.commonmark.node.Node
@@ -44,14 +45,9 @@ internal fun parseTos(markwon: Markwon, text: String):
List<TosSection> {
sections.add(TosSection(lastHeading, section))
section = Document()
}
- // check that this is a plain heading
- if (node.firstChild !is Text || node.firstChild.next != null) {
- throw ParseException(
- "Primary heading includes more than just text",
sections.size
- )
- }
- // start new section
- lastHeading = (node.firstChild as Text).literal
+ // start new section with new heading (stripped of markup)
+ lastHeading = getNodeText(node)
+ if (lastHeading.isBlank()) throw ParseException("Empty heading", 0)
} else if (lastHeading == null) {
throw ParseException("Found text before first primary heading", 0)
} else {
@@ -63,3 +59,17 @@ internal fun parseTos(markwon: Markwon, text: String):
List<TosSection> {
sections.add(TosSection(lastHeading, section))
return sections
}
+
+private fun getNodeText(rootNode: Node): String {
+ var node: Node? = rootNode.firstChild
+ var text = ""
+ while (node != null) {
+ text += when (node) {
+ is Text -> node.literal
+ is Code -> node.literal
+ else -> getNodeText(node)
+ }
+ node = node.next
+ }
+ return text
+}
--
To stop receiving notification emails like this one, please contact
address@hidden.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-taler-android] branch master updated: [wallet] accept but strip markup in ToS markdown headings,
gnunet <=