UIWebView incorrectly loads URLs that end with two equals sign characters from JavaScript on iOS 10

Originator:Josh.Lieberman92
Number:rdar://29035522 Date Originated:31-Oct-2016
Status:Open Resolved:
Product:iOS SDK Product Version:iOS 10
Classification:Other Bug Reproducible:Always
 
Summary:
In a UIWebView, when attempting to set a URL on the document.documentElement which ends in "==", the URL is incorrectly loaded as "about:blank" on iOS 10 devices.

Steps to Reproduce:
Download sample project.
Run sample application on an iOS 9 simulator or physical device (any model).
When the UIWebView loads, tap on the button that says "clickme."
Observe the correct URL is logged (onStatusChange://eyJ1c2VyTmFtZSI6IkpBTCIsLCJwcm92aWRlciI6IkVtYWlsIn0==)

Now stop the application and run it again on an iOS 10 simulator or physical device (any model).
When the UIWebView loads, tap on the button that says "clickme."
Observe that the URL is not logged, as the webview has tried to load  the "about:blank" page.

Expected Results:
I would expect the URL (onStatusChange://eyJ1c2VyTmFtZSI6IkpBTCIsLCJwcm92aWRlciI6IkVtYWlsIn0==) to load the same way on both iOS 9 and 10 runtimes.

Actual Results:
The iOS 10 runtime does not load the URL properly.

Version:
iOS 10.x.x

Notes:


Configuration:
Any iOS 9 and 10 devices or simulators

Attachments:
'WebViewSwift3.zip' was successfully uploaded.

Sample Code:

import UIKit

class ViewController: UIViewController {
    
    @IBOutlet weak var webView: UIWebView!
    
    var testHTML = "<html>" +
    "<body><input id=\"clickMe\" type=\"button\" value=\"clickme\" onclick=\"changeWindow();\" /></body>" +
    "<script type=\"text/javascript\">" +
    "function changeWindow() {" +
    "iFrame = this.createIFrame('onStatusChange://eyJ1c2VyTmFtZSI6IkpBTCIsLCJwcm92aWRlciI6IkVtYWlsIn0==');" +
    "iFrame.parentNode.removeChild(iFrame);" +
    "}" +
    "function createIFrame(src) {" +
    "var rootElm = document.documentElement;" +
    "var newFrameElm = document.createElement('IFRAME');" +
    "newFrameElm.setAttribute('src', src);" +
    "rootElm.appendChild(newFrameElm);" +
    "return newFrameElm;" +
    "}" +
    "</script>" +
    "</html>"

    override func viewDidLoad() {
        super.viewDidLoad()
        
        webView.loadHTMLString(testHTML, baseURL: nil)
        webView.delegate = self
    }
}

extension ViewController: UIWebViewDelegate {
    
    func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool {
        print(request.url!.absoluteString)
        
        return true
    }
    
    func webView(_ webView: UIWebView, didFailLoadWithError error: Error) {
        print(error)
    }
}

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!