File tree Expand file tree Collapse file tree 2 files changed +31
-21
lines changed
allure-generator/src/main/javascript/helpers Expand file tree Collapse file tree 2 files changed +31
-21
lines changed Original file line number Diff line number Diff line change 1- import { SafeString } from "handlebars/runtime" ;
1+ import { escapeExpression , SafeString } from "handlebars/runtime" ;
22
33const URL_REGEXP = / ^ ( \w ) + : \/ \/ .* / ;
44
55export default function ( text ) {
6- return URL_REGEXP . test ( text )
7- ? new SafeString ( `<a href="${ text } " class="link" target="_blank">${ text } </a>` )
8- : text ;
6+ if ( ! URL_REGEXP . test ( text ) ) {
7+ return text ;
8+ }
9+
10+ const safeText = escapeExpression ( text ) ;
11+
12+ return new SafeString (
13+ `<a href="${ safeText } " class="link" target="_blank" rel="noopener noreferrer">${ safeText } </a>`
14+ ) ;
915}
Original file line number Diff line number Diff line change 1- import { SafeString } from "handlebars/runtime" ;
1+ import { escapeExpression , SafeString } from "handlebars/runtime" ;
22
3- const URL_REGEXP = / ( (?: ( h t t p s ? : \/ \/ | f t p : \/ \/ | m a i l t o : ) | w w w \. ) \S + ?) ( \s | " | ' | \) | ] | } | & # 6 2 | $ ) / gm;
4-
5- const encodeHTMLEntities = ( rawString ) =>
6- rawString . replace ( / [ \u00A0 - \u9999 < > & ] / gim, ( i ) => `&#${ i . charCodeAt ( 0 ) } ;` ) ;
3+ const URL_REGEXP =
4+ / ( (?: ( h t t p s ? : \/ \/ | f t p : \/ \/ | m a i l t o : ) | w w w \. ) \S + ?) ( \s | " | ' | \) | ] | } | & # 6 2 | $ ) / gm;
75
86export default function ( text ) {
97 const hasUrl = text !== undefined && text . match ( URL_REGEXP ) ;
10- return hasUrl
11- ? new SafeString (
12- encodeHTMLEntities ( text ) . replace (
13- URL_REGEXP ,
14- ( _ , urlFullText , urlProtocol , terminalSymbol ) => {
15- return `<a class="link" target="_blank" href="${
16- urlProtocol ? urlFullText : `https://${ urlFullText } `
17- } ">${ urlFullText } </a>${ terminalSymbol } `;
18- } ,
19- ) ,
20- )
21- : text ;
8+
9+ if ( ! hasUrl ) {
10+ return text ;
11+ }
12+
13+ const escapedText = escapeExpression ( text ) ;
14+
15+ return new SafeString (
16+ escapedText . replace (
17+ URL_REGEXP ,
18+ ( _ , urlFullText , urlProtocol , terminalSymbol ) => {
19+ const href = urlProtocol ? urlFullText : `https://${ urlFullText } ` ;
20+
21+ // eslint-disable-next-line max-len
22+ return `<a class="link" target="_blank" href="${ href } " rel="noopener noreferrer">${ urlFullText } </a>${ terminalSymbol } ` ;
23+ } ,
24+ ) ,
25+ ) ;
2226}
You can’t perform that action at this time.
0 commit comments