Skip to content

Commit

Permalink
Convert several of XHR open()'s arguments to strings
Browse files Browse the repository at this point in the history
  • Loading branch information
Zirro authored and domenic committed Apr 1, 2018
1 parent 5e86716 commit 8ad6b17
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Expand Up @@ -183,7 +183,7 @@
"max-statements": "off",
"max-statements-per-line": ["error", { "max": 1 }],
"multiline-ternary": ["error", "always-multiline"],
"new-cap": ["error", { "capIsNewExceptions": ["USVString", "DOMString"] }],
"new-cap": ["error", { "capIsNewExceptions": ["ByteString", "USVString", "DOMString"] }],
"new-parens": "error",
"newline-per-chained-call": "off",
"no-array-constructor": "error",
Expand Down
27 changes: 14 additions & 13 deletions lib/jsdom/living/xmlhttprequest.js
Expand Up @@ -409,7 +409,7 @@ module.exports = function createXMLHttpRequest(window) {
}
return Object.keys(properties.responseHeaders)
.filter(key => properties.filteredResponseHeaders.indexOf(key) === -1)
.map(key => [toByteString(key).toLowerCase(), properties.responseHeaders[key]].join(": "))
.map(key => [conversions.ByteString(key).toLowerCase(), properties.responseHeaders[key]].join(": "))
.join("\r\n");
}

Expand All @@ -419,7 +419,7 @@ module.exports = function createXMLHttpRequest(window) {
if (readyState === XMLHttpRequest.UNSENT || readyState === XMLHttpRequest.OPENED) {
return null;
}
const lcHeader = toByteString(header).toLowerCase();
const lcHeader = conversions.ByteString(header).toLowerCase();
if (properties.filteredResponseHeaders.find(filtered => lcHeader === filtered.toLowerCase())) {
return null;
}
Expand All @@ -436,7 +436,16 @@ module.exports = function createXMLHttpRequest(window) {
if (argumentCount < 2) {
throw new TypeError("Not enough arguments (expected at least 2)");
}
method = toByteString(method);

method = conversions.ByteString(method);
uri = conversions.USVString(uri);
if (user) {
user = conversions.USVString(user);
}
if (password) {
password = conversions.USVString(password);
}

if (!tokenRegexp.test(method)) {
throw new DOMException("The string did not match the expected pattern.", "SyntaxError");
}
Expand Down Expand Up @@ -737,8 +746,8 @@ module.exports = function createXMLHttpRequest(window) {
if (arguments.length !== 2) {
throw new TypeError("2 arguments required for setRequestHeader");
}
header = toByteString(header);
value = toByteString(value);
header = conversions.ByteString(header);
value = conversions.ByteString(value);

if (this.readyState !== XMLHttpRequest.OPENED || properties.send) {
throw new DOMException("The object is in an invalid state.", "InvalidStateError");
Expand Down Expand Up @@ -978,14 +987,6 @@ module.exports = function createXMLHttpRequest(window) {
return XMLHttpRequest;
};

function toByteString(value) {
value = String(value);
if (!/^[\0-\xFF]*$/.test(value)) {
throw new TypeError("invalid ByteString");
}
return value;
}

function finalMIMEType(xhr) {
const flag = xhr[xhrSymbols.flag];
return flag.overrideMIMEType || getResponseHeader(xhr, "content-type");
Expand Down

0 comments on commit 8ad6b17

Please sign in to comment.