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 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 return uiLocation.linkText(); | 443 return uiLocation.linkText(); |
444 } | 444 } |
445 | 445 |
446 /** | 446 /** |
447 * @param {string} string | 447 * @param {string} string |
448 * @param {function(string,string,number=,number=):!Node} linkifier | 448 * @param {function(string,string,number=,number=):!Node} linkifier |
449 * @return {!DocumentFragment} | 449 * @return {!DocumentFragment} |
450 */ | 450 */ |
451 WebInspector.linkifyStringAsFragmentWithCustomLinkifier = function(string, linki
fier) | 451 WebInspector.linkifyStringAsFragmentWithCustomLinkifier = function(string, linki
fier) |
452 { | 452 { |
| 453 // Spec: https://url.spec.whatwg.org/#url-code-points |
453 var container = createDocumentFragment(); | 454 var container = createDocumentFragment(); |
454 var linkStringRegEx = /(?:[a-zA-Z][a-zA-Z0-9+.-]{2,}:\/\/|data:|www\.)[\w$\-
_+*'=\|\/\\(){}[\]^%@&#~,:;.!?]{2,}[\w$\-_+*=\|\/\\({^%@&#~]/; | 455 var protocol = "(?:[a-zA-Z][a-zA-Z0-9]{2,}://"; |
| 456 var userPassLogin = "(?:\\w+(?::\\w+)?@)?"; |
| 457 var domainOrIPV4 = "[a-zA-Z0-9](?:[a-zA-Z0-9]*|(?:-|\\.)[a-zA-Z0-9]+)+"; |
| 458 var ipv6 = "\\[(?:(?::|\\.)?[a-zA-Z0-9]{0,4}){2,8}\\]"; |
| 459 var portPattern = "(?::[0-9]{1,4})"; |
| 460 var domainPattern = "(?:" + ipv6 + "|" + domainOrIPV4 + ")" + portPattern +
"?"; |
| 461 var encodedURIPattern = "%[0-9]{2}"; |
| 462 var mayContainPunctuationIfNoSpaceAfter = "[.,:;](?!\\s|$)"; |
| 463 var uriPattern = "(?:(?:\\?|/|#)(?:[\\w" + |
| 464 "!$&'()*+\\-/=?#@_~" + |
| 465 "\\u{00A0}-\\u{D7FF}" + |
| 466 "\\u{E000}-\\u{FDCF}" + |
| 467 "\\u{FDF0}-\\u{FFFD}" + |
| 468 "\\u{10000}-\\u{1FFFD}" + |
| 469 "\\u{20000}-\\u{2FFFD}" + |
| 470 "\\u{30000}-\\u{3FFFD}" + |
| 471 "\\u{40000}-\\u{4FFFD}" + |
| 472 "\\u{50000}-\\u{5FFFD}" + |
| 473 "\\u{60000}-\\u{6FFFD}" + |
| 474 "\\u{70000}-\\u{7FFFD}" + |
| 475 "\\u{80000}-\\u{8FFFD}" + |
| 476 "\\u{90000}-\\u{9FFFD}" + |
| 477 "\\u{A0000}-\\u{AFFFD}" + |
| 478 "\\u{B0000}-\\u{BFFFD}" + |
| 479 "\\u{C0000}-\\u{CFFFD}" + |
| 480 "\\u{D0000}-\\u{DFFFD}" + |
| 481 "\\u{E0000}-\\u{EFFFD}" + |
| 482 "\\u{F0000}-\\u{FFFFD}" + |
| 483 "\\u{100000}-\\u{10FFFD}" + |
| 484 "]*|" + mayContainPunctuationIfNoSpaceAfter + "|" + encodedURIPattern +
")*)?"; |
| 485 var beginInPunctuationOrSpace = "([;:.,\\s;]|^)"; |
| 486 var endInPunctuationOrSpace = "(?=[;:.,\\s;]|$)"; |
| 487 var dataURI = "data:[^,]*,"; |
| 488 var protocolPattern = protocol + userPassLogin + domainPattern + "|www\\.(?:
" + domainOrIPV4 + ")" + portPattern + "?)"; |
| 489 var doubleQuotes = "\"(?:" + protocolPattern + "|" + dataURI + ")[^\"]*(?=\"
)"; |
| 490 var singleQuotes = "'(?:" + protocolPattern + "|" + dataURI + ")[^']*(?=')"; |
| 491 var accentQuotes = "`(?:" + protocolPattern + "|" + dataURI + ")[^`]*(?=`)"; |
| 492 var parenthesis = "\\((?:" + protocolPattern + "|" + dataURI + ")[^)]*(?=\\)
)"; |
| 493 var squareBrackets = "\\[(?:" + protocolPattern + "|" + dataURI + ")[^\\]]*(
?=\\])"; |
| 494 var linkStringRegEx = new RegExp("(?:(?:" + doubleQuotes + "|" + singleQuote
s + "|" + accentQuotes + "|" + parenthesis + "|" + squareBrackets + ")|" + begin
InPunctuationOrSpace + protocolPattern + uriPattern + endInPunctuationOrSpace +
")", "u"); |
455 | 495 |
456 while (string && string.length < WebInspector.Linkifier.MaxLengthToIgnoreLin
kifier) { | 496 while (string && string.length < WebInspector.Linkifier.MaxLengthToIgnoreLin
kifier) { |
457 var linkString = linkStringRegEx.exec(string); | 497 var match = linkStringRegEx.exec(string); |
458 if (!linkString) | 498 if (!match) |
459 break; | 499 break; |
| 500 var linkString = match[0]; |
| 501 var firstChar = linkString[0]; |
| 502 if (firstChar === "'" || firstChar === "\"" || firstChar === "`" || firs
tChar === "(" || firstChar === "[") { |
| 503 match.index += 1; |
| 504 linkString = linkString.substr(1); |
| 505 } |
| 506 var nonAlphaNumericFirstCharacter = match[1] |
| 507 if (nonAlphaNumericFirstCharacter) { |
| 508 // Unmatches/removes beginInPunctuationOrSpace from match. |
| 509 match.index += nonAlphaNumericFirstCharacter.length; |
| 510 linkString = linkString.substr(nonAlphaNumericFirstCharacter.length)
; |
| 511 } |
460 | 512 |
461 linkString = linkString[0]; | 513 |
462 var linkIndex = string.indexOf(linkString); | 514 var linkIndex = match.index; |
463 var nonLink = string.substring(0, linkIndex); | 515 var nonLink = string.substring(0, linkIndex); |
464 container.appendChild(createTextNode(nonLink)); | 516 container.appendChild(createTextNode(nonLink)); |
465 | 517 |
466 var title = linkString; | 518 var title = linkString; |
467 var realURL = (linkString.startsWith("www.") ? "http://" + linkString :
linkString); | 519 var realURL = (linkString.startsWith("www.") ? "http://" + linkString :
linkString); |
468 var splitResult = WebInspector.ParsedURL.splitLineAndColumn(realURL); | 520 var splitResult = WebInspector.ParsedURL.splitLineAndColumn(realURL); |
469 var linkNode; | 521 var linkNode; |
470 if (splitResult) | 522 if (splitResult) |
471 linkNode = linkifier(title, splitResult.url, splitResult.lineNumber,
splitResult.columnNumber); | 523 linkNode = linkifier(title, splitResult.url, splitResult.lineNumber,
splitResult.columnNumber); |
472 else | 524 else |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 /** | 586 /** |
535 * @param {!WebInspector.NetworkRequest} request | 587 * @param {!WebInspector.NetworkRequest} request |
536 * @return {!Element} | 588 * @return {!Element} |
537 */ | 589 */ |
538 WebInspector.linkifyRequestAsNode = function(request) | 590 WebInspector.linkifyRequestAsNode = function(request) |
539 { | 591 { |
540 var anchor = WebInspector.linkifyURLAsNode(request.url); | 592 var anchor = WebInspector.linkifyURLAsNode(request.url); |
541 anchor.requestId = request.requestId; | 593 anchor.requestId = request.requestId; |
542 return anchor; | 594 return anchor; |
543 } | 595 } |
OLD | NEW |