Skip to content

Commit

Permalink
ChangeUrl to accept an encoded string
Browse files Browse the repository at this point in the history
  • Loading branch information
dotjs authored and ariya committed Apr 29, 2013
1 parent f72f296 commit 3ae632e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/networkaccessmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,11 @@ void JsNetworkRequest::abort()
}


void JsNetworkRequest::changeUrl(const QString& url)
void JsNetworkRequest::changeUrl(const QString& address)
{
if (m_networkRequest) {
m_networkRequest->setUrl(QUrl(url));
QUrl url = QUrl::fromEncoded(QByteArray(address.toAscii()));
m_networkRequest->setUrl(url);
}
}

Expand Down
35 changes: 35 additions & 0 deletions test/webpage-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,41 @@ describe("WebPage object", function() {
});
});


it("should change a url request with an encoded query string", function() {
var page = new require('webpage').create();

var server = require('webserver').create();
server.listen(12345, function(request, response) {
// echo received request headers in response body
response.write(JSON.stringify(request.headers));
response.close();
});

var url = "http://localhost:12345/cdn-cgi/pe/bag?r%5B%5D=http%3A%2F%2Fwww.example.org%2Fcdn-cgi%2Fnexp%2Fabv%3D927102467%2Fapps%2Fabetterbrowser.js";

var handled = false;
runs(function() {
expect(handled).toEqual(false);

page.onResourceRequested = function(requestData, request) {
request.changeUrl(requestData.url);
};

page.onResourceReceived = function(data) {
if (data['stage'] === 'end') {
expect(data.url).toEqual(url);
}
};

page.open(url, function (status) {
expect(status == 'success').toEqual(true);
handled = true;
});
});
});


it('should able to abort a network request', function() {
var page = require('webpage').create();
var url = 'http://phantomjs.org';
Expand Down

0 comments on commit 3ae632e

Please sign in to comment.