Skip to content

Commit

Permalink
fix: assets loading with mixed <script> tags
Browse files Browse the repository at this point in the history
fixes 15773
  • Loading branch information
BrayanDSO authored and lukstbit committed Mar 5, 2024
1 parent a5e9c2b commit 1bc053c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ fun parseVideos(text: String, mediaDir: String): String {
@NotInLibAnki
@VisibleForTesting
fun parseSourcesToFileScheme(content: String, mediaDir: String): String {
val doc = Jsoup.parse(content)
val doc = Jsoup.parseBodyFragment(content)
doc.outputSettings(OutputSettings().prettyPrint(false))

fun replaceWithFileScheme(tag: String, attr: String): Boolean {
Expand Down
27 changes: 27 additions & 0 deletions AnkiDroid/src/test/java/com/ichi2/libanki/TemplateManagerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,33 @@ class TemplateManagerTest {
assertEquals("""<img src="file:///storage/emulated/0/AnkiDroid@%23$%25/collection.media/magenta.png">""", result)
}

@Test
fun `parseSourcesToFileScheme - mixed script`() {
@Language("HTML")
val input = """
<!-- VERSION 1.14 -->
<script>
var scroll = false;
</script>
<img src="lovely.jpg">
<!-- ENHANCED_CLOZE -->
hughes and kisses
"""

@Language("HTML")
val expectedResult = """
<!-- VERSION 1.14 -->
<script>
var scroll = false;
</script>
<img src="file:///storage/emulated/0/15773/collection.media/lovely.jpg">
<!-- ENHANCED_CLOZE -->
hughes and kisses
"""
val result = parseSourcesToFileScheme(input, "/storage/emulated/0/15773/collection.media")
assertEquals(expectedResult, result)
}

/***********************************************************************************************
* [parseVideos] tests
**********************************************************************************************/
Expand Down

0 comments on commit 1bc053c

Please sign in to comment.