Merge pull request #3852 from swagger-api/bug/3851-validatorurl-sanitization-type
Check for input type and string length before sanitizing a URL
This commit is contained in:
@@ -723,6 +723,10 @@ export const shallowEqualKeys = (a,b, keys) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function sanitizeUrl(url) {
|
export function sanitizeUrl(url) {
|
||||||
|
if(typeof url !== "string" || url === "") {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
return braintreeSanitizeUrl(url)
|
return braintreeSanitizeUrl(url)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -912,5 +912,17 @@ sbG8iKTs8L3NjcmlwdD4=`)
|
|||||||
|
|
||||||
expect(res).toEqual("https://swagger.io/")
|
expect(res).toEqual("https://swagger.io/")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("should gracefully handle empty strings", function() {
|
||||||
|
expect(sanitizeUrl("")).toEqual("")
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should gracefully handle non-string values", function() {
|
||||||
|
expect(sanitizeUrl(123)).toEqual("")
|
||||||
|
expect(sanitizeUrl(null)).toEqual("")
|
||||||
|
expect(sanitizeUrl(undefined)).toEqual("")
|
||||||
|
expect(sanitizeUrl([])).toEqual("")
|
||||||
|
expect(sanitizeUrl({})).toEqual("")
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user