|
1 | 1 | import {EmailMatch, ExtractCertainUriMatch, IndexContainingBaseMatch, NoProtocolJsnParamType} from "../types"; |
2 | 2 | import {SafeConditionalUrlPatternBuilder} from "../pattern/SafeConditionalUrlPatternBuilder"; |
3 | | - |
4 | | -import {DomainPatterns} from "../pattern/DomainPatterns"; |
5 | 3 | import {TextAreaService} from "../service/TextAreaService"; |
| 4 | +import {processAllUriMatches} from "../bo/UriMatchProcessor"; |
6 | 5 |
|
7 | 6 | export const TextAreaApi = { |
8 | 7 |
|
@@ -69,61 +68,10 @@ export const TextAreaApi = { |
69 | 68 | throw new Error('the variable textStr must be a string type and not be null.'); |
70 | 69 | } |
71 | 70 |
|
72 | | - let obj: IndexContainingBaseMatch[] = TextAreaService.extractCertainPureUris(textStr, uris, endBoundary); |
73 | | - let obj2: IndexContainingBaseMatch[] = TextAreaService.extractAllPureUrls(textStr); |
74 | | - |
75 | | - |
76 | | - //console.log('obj : ' + JSON.stringify(obj)); |
77 | | - |
78 | | - let obj_final = []; |
79 | | - |
80 | | - for (let a = 0; a < obj.length; a++) { |
81 | | - |
82 | | - let obj_part: ExtractCertainUriMatch = { |
83 | | - uriDetected: undefined, |
84 | | - inWhatUrl: undefined, |
85 | | - }; |
86 | | - |
87 | | - //let matchedUrlFound = false; |
88 | | - for (let b = 0; b < obj2.length; b++) { |
89 | | - |
90 | | - if ((obj[a].index.start > obj2[b].index.start && obj[a].index.start < obj2[b].index.end) |
91 | | - && |
92 | | - (obj[a].index.end > obj2[b].index.start && obj[a].index.end <= obj2[b].index.end)) { |
93 | | - |
94 | | - // Here, the uri detected is inside its url |
95 | | - // false positives like the example '//google.com/abc/def?a=5&b=7' can be detected in 'Service.Text.extractCertainPureUris' |
96 | | - |
97 | | - let sanitizedUrl = obj[a]['value']['url'] || ""; |
98 | | - |
99 | | - let rx = new RegExp('^(\\/\\/[^/]*|\\/[^\\s]+\\.' + DomainPatterns.allRootDomains + ')', 'gi'); |
100 | | - let matches = []; |
101 | | - let match: RegExpExecArray | null; |
102 | | - |
103 | | - while ((match = rx.exec(obj[a].value.url || "")) !== null) { |
104 | | - if (match[1]) { |
105 | | - |
106 | | - sanitizedUrl = sanitizedUrl.replace(rx, ''); |
107 | | - |
108 | | - //console.log(match[1]); |
109 | | - |
110 | | - obj[a].value.url = sanitizedUrl; |
111 | | - obj[a].index.start += match[1].length; |
112 | | - |
113 | | - obj[a].value.onlyUriWithParams = obj[a].value.url; |
114 | | - obj[a].value.onlyUri = (obj[a].value.url || "").replace(/\?[^/]*$/gi, ''); |
115 | | - } |
116 | | - } |
117 | | - obj_part.inWhatUrl = obj2[b]; |
118 | | - } |
119 | | - |
120 | | - } |
121 | | - |
122 | | - obj_part.uriDetected = obj[a]; |
123 | | - obj_final.push(obj_part); |
124 | | - } |
| 71 | + let uriMatchList: IndexContainingBaseMatch[] = TextAreaService.extractCertainPureUris(textStr, uris, endBoundary); |
| 72 | + let urlMatchList: IndexContainingBaseMatch[] = TextAreaService.extractAllPureUrls(textStr); |
125 | 73 |
|
126 | | - return obj_final; |
| 74 | + return processAllUriMatches(uriMatchList, urlMatchList); |
127 | 75 |
|
128 | 76 | }, |
129 | 77 |
|
|
0 commit comments