Skip to content

Commit

Permalink
chore: encode loadPage action url
Browse files Browse the repository at this point in the history
  • Loading branch information
mrehan27 committed Dec 26, 2024
1 parent 9f5b69c commit ab879eb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Sources/MessagingInApp/Gist/Managers/MessageManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ class MessageManager: EngineWebDelegate {
logger.logWithModuleTag("Dismissing from action: \(action)", level: .info)
inAppMessageManager.dispatch(action: .dismissMessage(message: currentMessage, viaCloseAction: true))
case "loadPage":
if let page = url.queryParameters?["url"],
// Encode '#' in url action string and creates encoded URL to handle fragments
let encodedUrl = URL(string: action.percentEncode(character: "#")) ?? url
if let page = encodedUrl.queryParameters?["url"],
let pageUrl = URL(string: page),
UIApplication.shared.canOpenURL(pageUrl) {
UIApplication.shared.open(pageUrl)
Expand Down
8 changes: 8 additions & 0 deletions Sources/MessagingInApp/Gist/Utilities/String.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Foundation

extension String {
/// Encodes a specific character in the string using percent encoding.
func percentEncode(character target: String, withAllowedCharacters allowedCharacters: CharacterSet = .urlPathAllowed) -> String {
replacingOccurrences(of: target, with: target.addingPercentEncoding(withAllowedCharacters: allowedCharacters) ?? target)
}
}

0 comments on commit ab879eb

Please sign in to comment.