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 + ") *)?"; | |
lushnikov
2016/07/06 22:56:56
nit: indent
allada
2016/07/07 02:06:50
Done.
| |
485 var beginInPunctuationOrSpace = "([;:.,\\s;]|^)"; | |
486 var endInPunctuationOrSpace = "(?=[;:.,\\s;]|$)"; | |
487 var dataURI = "data:[^,]*," | |
lushnikov
2016/07/06 22:56:56
nit:semicolon is missing here and below
allada
2016/07/07 02:06:50
Done.
| |
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 linkStringRegEx = new RegExp("(?:(?:" + doubleQuotes + "|" + singleQuote s + "|" + accentQuotes + ")|" + beginInPunctuationOrSpace + protocolPattern + ur iPattern + endInPunctuationOrSpace + ")", "u"); | |
455 | 493 |
456 while (string && string.length < WebInspector.Linkifier.MaxLengthToIgnoreLin kifier) { | 494 while (string && string.length < WebInspector.Linkifier.MaxLengthToIgnoreLin kifier) { |
457 var linkString = linkStringRegEx.exec(string); | 495 var match = linkStringRegEx.exec(string); |
458 if (!linkString) | 496 if (!match) |
459 break; | 497 break; |
498 var linkString = match[0]; | |
499 var firstChar = linkString.substr(0, 1); | |
lushnikov
2016/07/06 22:56:56
linkString[0]
allada
2016/07/07 02:06:50
Done.
| |
500 if (firstChar === "'" || firstChar === "\"" || firstChar === "`") { | |
501 match.index += 1; | |
lushnikov
2016/07/06 22:56:56
why do we truncate only from beginning? What about
allada
2016/07/07 02:06:50
Because it uses lookaheads in the regex instead of
| |
502 linkString = linkString.substr(1); | |
503 } | |
504 if (match[1]) { | |
lushnikov
2016/07/06 22:56:56
What is match[1]? Is this another group captured b
allada
2016/07/07 02:06:50
Done.
| |
505 // Unmatches/removes beginInPunctuationOrSpace from match | |
lushnikov
2016/07/06 22:56:56
nit: comments should end with dot
allada
2016/07/07 02:06:50
Done.
| |
506 match.index += match[1].length; | |
507 linkString = linkString.substr(match[1].length); | |
508 } | |
460 | 509 |
461 linkString = linkString[0]; | 510 |
462 var linkIndex = string.indexOf(linkString); | 511 var linkIndex = match.index; |
463 var nonLink = string.substring(0, linkIndex); | 512 var nonLink = string.substring(0, linkIndex); |
464 container.appendChild(createTextNode(nonLink)); | 513 container.appendChild(createTextNode(nonLink)); |
465 | 514 |
466 var title = linkString; | 515 var title = linkString; |
467 var realURL = (linkString.startsWith("www.") ? "http://" + linkString : linkString); | 516 var realURL = (linkString.startsWith("www.") ? "http://" + linkString : linkString); |
468 var splitResult = WebInspector.ParsedURL.splitLineAndColumn(realURL); | 517 var splitResult = WebInspector.ParsedURL.splitLineAndColumn(realURL); |
469 var linkNode; | 518 var linkNode; |
470 if (splitResult) | 519 if (splitResult) |
471 linkNode = linkifier(title, splitResult.url, splitResult.lineNumber, splitResult.columnNumber); | 520 linkNode = linkifier(title, splitResult.url, splitResult.lineNumber, splitResult.columnNumber); |
472 else | 521 else |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
534 /** | 583 /** |
535 * @param {!WebInspector.NetworkRequest} request | 584 * @param {!WebInspector.NetworkRequest} request |
536 * @return {!Element} | 585 * @return {!Element} |
537 */ | 586 */ |
538 WebInspector.linkifyRequestAsNode = function(request) | 587 WebInspector.linkifyRequestAsNode = function(request) |
539 { | 588 { |
540 var anchor = WebInspector.linkifyURLAsNode(request.url); | 589 var anchor = WebInspector.linkifyURLAsNode(request.url); |
541 anchor.requestId = request.requestId; | 590 anchor.requestId = request.requestId; |
542 return anchor; | 591 return anchor; |
543 } | 592 } |
OLD | NEW |