Skip to content

Commit

Permalink
html document exchange for form, link, and location follows did not u…
Browse files Browse the repository at this point in the history
…se the final request url (after redirect for example) to set the new document.location internal values and in some cases was set with a relative path resulting in an empty host and protocol component. thanks to ventura again for helping identify this one
  • Loading branch information
thatcher committed Aug 11, 2010
1 parent db4c817 commit 9ae9185
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion build.properties
Expand Up @@ -2,7 +2,7 @@
PROJECT: env-js
BUILD_MAJOR: 1
BUILD_MINOR: 2
BUILD_ID: 21
BUILD_ID: 22
BUILD_VERSION: ${BUILD_MAJOR}.${BUILD_MINOR}.${BUILD_ID}
BUILD: ${PROJECT}.${BUILD_VERSION}
VERSION: ${BUILD} ${DSTAMP}
Expand Down
5 changes: 1 addition & 4 deletions src/platform/core/xhr.js
Expand Up @@ -37,10 +37,7 @@ Envjs.uri = function(path, base) {
// Ideally I would like the caller to pass in document.baseURI to
// make this more self-sufficient and testable
if (!base && document) {
if(document.baseURI)
base = document.baseURI;
else
base = window.location.protocol + ":" + window.location.host;
base = document.baseURI;
}

// about:blank doesn't count
Expand Down
7 changes: 3 additions & 4 deletions src/xhr/a.js
Expand Up @@ -9,17 +9,16 @@ HTMLAnchorElement.prototype.click = function(){
xhr = new XMLHttpRequest();
method = this.method !== ""?this.method:"GET";
url = Envjs.uri(this.href, this.ownerDocument.baseURI);
xhr.open(method, url, false);
xhr.send(url, false);
xhr.open(method, url, false);//synchronous
xhr.send(url, false);//dont parse html
if(xhr.readyState === 4){
/*console.log('%s new document text ready for parse and exchange %s \n %s',
this.ownerDocument.baseURI,
url,
xhr.responseText
);*/
__exchangeHTMLDocument__(this.ownerDocument, xhr.responseText, url, this.ownerDocument.__ownerFrame__);
__exchangeHTMLDocument__(this.ownerDocument, xhr.responseText, xhr.url, this.ownerDocument.__ownerFrame__);
//DOMContentLoaded event
//console.log('finished document exchange %s', this.ownerDocument.baseURI);
}
};

6 changes: 3 additions & 3 deletions src/xhr/form.js
Expand Up @@ -16,15 +16,15 @@ HTMLFormElement.prototype.submit = function(){
this.action !== ""?this.action:this.ownerDocument.baseURI,
this.ownerDocument.baseURI
);
xhr.open(method, action, false);
xhr.send(serialized, false);
xhr.open(method, action, false);//synchronous
xhr.send(serialized, false);//dont parse html
if(xhr.readyState === 4){
/*console.log('%s new document text ready for parse and exchange %s \n %s',
this.ownerDocument.baseURI,
action,
xhr.responseText
);*/
__exchangeHTMLDocument__(this.ownerDocument, xhr.responseText, action, this.ownerDocument.__ownerFrame__);
__exchangeHTMLDocument__(this.ownerDocument, xhr.responseText, xhr.url, this.ownerDocument.__ownerFrame__);
//DOMContentLoaded event
//console.log('finished document exchange %s', this.ownerDocument.baseURI);
}
Expand Down
7 changes: 3 additions & 4 deletions src/xhr/location.js
Expand Up @@ -190,18 +190,17 @@ Location = function(url, doc, history) {
xhr.onreadystatechange = function() {
//console.log('readyState %s', xhr.readyState);
if (xhr.readyState === 4) {
$document.baseURI = new Location(url, $document);
//console.log('new document baseURI %s', $document.baseURI);
__exchangeHTMLDocument__($document, xhr.responseText, url);
__exchangeHTMLDocument__($document, xhr.responseText, xhr.url);
}
};
xhr.send(null, false);
xhr.send(null, false);//dont parse html
} else {
//Treat as an XMLDocument
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
$document = xhr.responseXML;
$document.baseURI = $url;
$document.baseURI = xhr.url;
if ($document.createEvent) {
event = $document.createEvent('Event');
event.initEvent('DOMContentLoaded');
Expand Down
2 changes: 2 additions & 0 deletions src/xhr/xmlhttprequest.js
Expand Up @@ -38,6 +38,7 @@ XMLHttpRequest.prototype = {
},
send: function(data, parsedoc/*non-standard*/, redirect_count){
var _this = this;
//console.log('sending request for url %s', this.url);
parsedoc = (parsedoc === undefined)?true:!!parsedoc;
redirect_count = (redirect_count === undefined) ? 0 : redirect_count
function makeRequest(){
Expand All @@ -62,6 +63,7 @@ XMLHttpRequest.prototype = {

if(_this.status === 302 && _this.getResponseHeader('Location') && redirect_count < 20){
//follow redirect and copy headers
//console.log('following redirect from %s url %s', _this.url, _this.getResponseHeader('Location'));
_this.url = Envjs.uri(_this.getResponseHeader('Location'));
//remove current cookie headers to allow the redirect to determine
//the currect cookie based on the new location
Expand Down

0 comments on commit 9ae9185

Please sign in to comment.