Permalink
Browse files

Use regex to replace trailing slashes from browser-policy URLs.

Thanks glasser!
  • Loading branch information...
1 parent 189845f commit bdf6fd248574997f2d5da462d031a57139d135bd Emily Stark committed Jan 14, 2014
Showing with 3 additions and 4 deletions.
  1. +3 −4 packages/browser-policy-content/browser-policy-content.js
@@ -90,17 +90,16 @@ var prepareForCspDirective = function (directive) {
// cross-browser behavior; some browsers interpret an origin without a
// protocol as http://<src> and some interpret it as both http://<src>
// and https://<src>
-// - Trim trailing slashes from `src`.
+// - Trim trailing slashes from `src`, since some browsers interpret
+// "foo.com/" as "foo.com" and some don't.
var addSourceForDirective = function (directive, src) {
if (_.contains(_.values(keywords), src)) {
cspSrcs[directive].push(src);
} else {
src = src.toLowerCase();
// Trim trailing slashes.
- while (src.charAt(src.length - 1) === "/") {
- src = src.substring(0, src.length - 1);
- }
+ src = src.replace(/\/+$/, '');
var toAdd = [];
// If there is no protocol, add both http:// and https://.

0 comments on commit bdf6fd2

Please sign in to comment.