| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * | 10 * |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 for (var i = 1; i < splittedPath.length; ++i) { | 114 for (var i = 1; i < splittedPath.length; ++i) { |
| 115 if (!splittedPath[i]) | 115 if (!splittedPath[i]) |
| 116 continue; | 116 continue; |
| 117 result.push(splittedPath[i]); | 117 result.push(splittedPath[i]); |
| 118 } | 118 } |
| 119 result.push(name); | 119 result.push(name); |
| 120 return result; | 120 return result; |
| 121 } | 121 } |
| 122 | 122 |
| 123 /** | 123 /** |
| 124 * http://tools.ietf.org/html/rfc3986#section-5.2.4 | |
| 125 * @param {string} path | |
| 126 * @return {string} | |
| 127 */ | |
| 128 | |
| 129 WebInspector.ParsedURL.normalizePath = function(path) | |
| 130 { | |
| 131 if (path.indexOf("..") === -1 && path.indexOf('.') === -1) | |
| 132 return path; | |
| 133 | |
| 134 var normalizedSegments = []; | |
| 135 var segments = path.split("/"); | |
| 136 for (var i = 0; i < segments.length; i++) { | |
| 137 var segment = segments[i]; | |
| 138 if (segment === ".") | |
| 139 continue; | |
| 140 else if (segment === "..") | |
| 141 normalizedSegments.pop(); | |
| 142 else if (segment) | |
| 143 normalizedSegments.push(segment); | |
| 144 } | |
| 145 var normalizedPath = normalizedSegments.join("/"); | |
| 146 if (normalizedPath[normalizedPath.length - 1] === "/") | |
| 147 return normalizedPath; | |
| 148 if (path[0] === "/" && normalizedPath) | |
| 149 normalizedPath = "/" + normalizedPath; | |
| 150 if ((path[path.length - 1] === "/") || (segments[segments.length - 1] === ".
") || (segments[segments.length - 1] === "..")) | |
| 151 normalizedPath = normalizedPath + "/"; | |
| 152 | |
| 153 return normalizedPath; | |
| 154 } | |
| 155 | |
| 156 /** | |
| 157 * @param {string} baseURL | 124 * @param {string} baseURL |
| 158 * @param {string} href | 125 * @param {string} href |
| 159 * @return {?string} | 126 * @return {?string} |
| 160 */ | 127 */ |
| 161 WebInspector.ParsedURL.completeURL = function(baseURL, href) | 128 WebInspector.ParsedURL.completeURL = function(baseURL, href) |
| 162 { | 129 { |
| 163 if (href) { | 130 if (href) { |
| 164 // Return special URLs as-is. | 131 // Return special URLs as-is. |
| 165 var trimmedHref = href.trim(); | 132 var trimmedHref = href.trim(); |
| 166 if (trimmedHref.startsWith("data:") || trimmedHref.startsWith("blob:") |
| trimmedHref.startsWith("javascript:")) | 133 if (trimmedHref.startsWith("data:") || trimmedHref.startsWith("blob:") |
| trimmedHref.startsWith("javascript:")) |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 var prefix = parsedURL.path; | 174 var prefix = parsedURL.path; |
| 208 var prefixQuery = prefix.indexOf("?"); | 175 var prefixQuery = prefix.indexOf("?"); |
| 209 if (prefixQuery !== -1) | 176 if (prefixQuery !== -1) |
| 210 prefix = prefix.substring(0, prefixQuery); | 177 prefix = prefix.substring(0, prefixQuery); |
| 211 prefix = prefix.substring(0, prefix.lastIndexOf("/")) + "/"; | 178 prefix = prefix.substring(0, prefix.lastIndexOf("/")) + "/"; |
| 212 path = prefix + path; | 179 path = prefix + path; |
| 213 } else if (path.length > 1 && path.charAt(1) === "/") { | 180 } else if (path.length > 1 && path.charAt(1) === "/") { |
| 214 // href starts with "//" which is a full URL with the protocol dropp
ed (use the baseURL protocol). | 181 // href starts with "//" which is a full URL with the protocol dropp
ed (use the baseURL protocol). |
| 215 return parsedURL.scheme + ":" + path + postfix; | 182 return parsedURL.scheme + ":" + path + postfix; |
| 216 } // else absolute path | 183 } // else absolute path |
| 217 return parsedURL.scheme + "://" + parsedURL.host + (parsedURL.port ? (":
" + parsedURL.port) : "") + WebInspector.ParsedURL.normalizePath(path) + postfix
; | 184 return parsedURL.scheme + "://" + parsedURL.host + (parsedURL.port ? (":
" + parsedURL.port) : "") + normalizePath(path) + postfix; |
| 218 } | 185 } |
| 219 return null; | 186 return null; |
| 220 } | 187 } |
| 221 | 188 |
| 222 WebInspector.ParsedURL.prototype = { | 189 WebInspector.ParsedURL.prototype = { |
| 223 get displayName() | 190 get displayName() |
| 224 { | 191 { |
| 225 if (this._displayName) | 192 if (this._displayName) |
| 226 return this._displayName; | 193 return this._displayName; |
| 227 | 194 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 /** | 238 /** |
| 272 * @return {?WebInspector.ParsedURL} | 239 * @return {?WebInspector.ParsedURL} |
| 273 */ | 240 */ |
| 274 String.prototype.asParsedURL = function() | 241 String.prototype.asParsedURL = function() |
| 275 { | 242 { |
| 276 var parsedURL = new WebInspector.ParsedURL(this.toString()); | 243 var parsedURL = new WebInspector.ParsedURL(this.toString()); |
| 277 if (parsedURL.isValid) | 244 if (parsedURL.isValid) |
| 278 return parsedURL; | 245 return parsedURL; |
| 279 return null; | 246 return null; |
| 280 } | 247 } |
| OLD | NEW |