瀏覽代碼

Check for input type and string length before sanitizing a URL

bubble
Kyle Shockey 6 年之前
父節點
當前提交
1aa1907128
共有 2 個文件被更改,包括 16 次插入0 次删除
  1. +4
    -0
      src/core/utils.js
  2. +12
    -0
      test/core/utils.js

+ 4
- 0
src/core/utils.js 查看文件

@@ -723,6 +723,10 @@ export const shallowEqualKeys = (a,b, keys) => {
}

export function sanitizeUrl(url) {
if(typeof url !== "string" || url === "") {
return ""
}

return braintreeSanitizeUrl(url)
}



+ 12
- 0
test/core/utils.js 查看文件

@@ -912,5 +912,17 @@ sbG8iKTs8L3NjcmlwdD4=`)

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("")
})
})
})

Loading…
取消
儲存