diff --git a/src/MyWebLog.Domain/ViewModels.fs b/src/MyWebLog.Domain/ViewModels.fs
index c5c93a3..b7620c9 100644
--- a/src/MyWebLog.Domain/ViewModels.fs
+++ b/src/MyWebLog.Domain/ViewModels.fs
@@ -21,7 +21,9 @@ module PublicHelpers =
/// post text
let addBaseToRelativeUrls extra (text: string) =
if extra = "" then text
- else text.Replace("href=\"/", $"href=\"{extra}/").Replace("src=\"/", $"src=\"{extra}/")
+ else
+ text.Replace("href=\"/", $"href=\"{extra}/").Replace("href=/", $"href={extra}/")
+ .Replace("src=\"/", $"src=\"{extra}/").Replace("src=/", $"src={extra}/")
/// The model used to display the admin dashboard
diff --git a/src/MyWebLog.Tests/ViewModelsTests.fs b/src/MyWebLog.Tests/ViewModelsTests.fs
index 86bc476..44847e4 100644
--- a/src/MyWebLog.Tests/ViewModelsTests.fs
+++ b/src/MyWebLog.Tests/ViewModelsTests.fs
@@ -8,16 +8,27 @@ open NodaTime
/// Unit tests for the addBaseToRelativeUrls helper function
let addBaseToRelativeUrlsTests = testList "PublicHelpers.addBaseToRelativeUrls" [
- test "succeeds when there is no extra URL path" {
- let testText = """Howdy>"""
+ test "succeeds for quoted URLs when there is no extra URL path" {
+ let testText = """"""
let modified = addBaseToRelativeUrls "" testText
Expect.equal modified testText "The text should not have been modified"
}
- test "succeeds with an extra URL path" {
+ test "succeeds for quoted URLs with an extra URL path" {
let testText =
- """link"""
let expected =
- """link"""
+ Expect.equal (addBaseToRelativeUrls "/a/b" testText) expected "Relative URLs not modified correctly"
+ }
+ test "succeeds for unquoted URLs when there is no extra URL path" {
+ let testText = ""
+ let modified = addBaseToRelativeUrls "" testText
+ Expect.equal modified testText "The text should not have been modified"
+ }
+ test "succeeds for unquoted URLs with an extra URL path" {
+ let testText = "link"
+ let expected =
+ "link"
Expect.equal (addBaseToRelativeUrls "/a/b" testText) expected "Relative URLs not modified correctly"
}
]