From c2d5d7043644cbd3e0a8bfe3d9251cc5eca811d4 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Thu, 18 May 2017 20:08:38 +0100 Subject: Avoid parsing URI when replacing fragment --- lib/docx/uris.js | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib/docx/uris.js') diff --git a/lib/docx/uris.js b/lib/docx/uris.js index 0179e5b..89d5be1 100644 --- a/lib/docx/uris.js +++ b/lib/docx/uris.js @@ -1,4 +1,5 @@ exports.uriToZipEntryName = uriToZipEntryName; +exports.replaceFragment = replaceFragment; function uriToZipEntryName(base, uri) { if (uri.charAt(0) === "/") { @@ -9,3 +10,12 @@ function uriToZipEntryName(base, uri) { return base + "/" + uri; } } + + +function replaceFragment(uri, fragment) { + var hashIndex = uri.indexOf("#"); + if (hashIndex !== -1) { + uri = uri.substring(0, hashIndex); + } + return uri + "#" + fragment; +} -- cgit v1.2.3