@@ -2,153 +2,11 @@ import type { SelectorConversion } from "../types";
2
2
3
3
import * as htmlparser2 from "htmlparser2" ;
4
4
import { escape as htmlEscape } from "html-escaper" ;
5
- import { log , obfuscateKeys } from "../utils" ;
5
+ import { obfuscateKeys } from "../utils" ;
6
6
import { obfuscateJs } from "./js" ;
7
7
import { cssUnescape } from "css-seasoning" ;
8
8
9
- /**
10
- * @deprecated
11
- */
12
- function findHtmlTagContentsRecursive (
13
- content : string ,
14
- targetTag : string ,
15
- targetClass : string | null = null ,
16
- foundTagContents : string [ ] = [ ] ,
17
- deep = 0 ,
18
- maxDeep = - 1 ,
19
- ) {
20
- let contentAfterTag = content ;
21
- const startTagWithClassRegexStr = targetClass
22
- ? // ref: https://stackoverflow.com/a/16559544
23
- `(<\\w+?\\s+?class\\s*=\\s*['\"][^'\"]*?\\b${ targetClass } \\b)`
24
- : "" ;
25
- const startTagRegexStr = `(<${ targetTag } [\\s|>])` ;
26
- const endTagRegexStr = `(<\/${ targetTag } >)` ;
27
-
28
- // clear content before the start tag
29
- const clearContentBeforeStartTagRegex = new RegExp (
30
- `${ startTagWithClassRegexStr ? startTagWithClassRegexStr + ".*|" + startTagRegexStr : startTagRegexStr + ".*" } ` ,
31
- "i" ,
32
- ) ;
33
- const contentAfterStartTagMatch = contentAfterTag . match (
34
- clearContentBeforeStartTagRegex ,
35
- ) ;
36
- if ( contentAfterStartTagMatch ) {
37
- contentAfterTag = contentAfterStartTagMatch [ 0 ] ;
38
- }
39
-
40
- let endTagCont = 0 ;
41
-
42
- const endTagContRegex = new RegExp ( endTagRegexStr , "gi" ) ;
43
- const endTagContMatch = contentAfterTag . match ( endTagContRegex ) ;
44
- if ( endTagContMatch ) {
45
- endTagCont = endTagContMatch . length ;
46
- }
47
-
48
- let closeTagPoition = 0 ;
49
-
50
- const tagPatternRegex = new RegExp (
51
- `${ startTagWithClassRegexStr ? startTagWithClassRegexStr + "|" + startTagRegexStr : startTagRegexStr } |${ endTagRegexStr } ` ,
52
- "gi" ,
53
- ) ;
54
- const tagPatternMatch = contentAfterTag . match ( tagPatternRegex ) ;
55
- if ( tagPatternMatch ) {
56
- let tagCount = 0 ;
57
- let markedPosition = false ;
58
- for ( let i = 0 ; i < tagPatternMatch . length ; i ++ ) {
59
- if ( tagPatternMatch [ i ] . startsWith ( "</" ) ) {
60
- if ( ! markedPosition ) {
61
- closeTagPoition = endTagCont - tagCount ;
62
- markedPosition = true ;
63
- }
64
- tagCount -- ;
65
- } else {
66
- tagCount ++ ;
67
- }
68
- if ( tagCount == 0 ) {
69
- break ;
70
- }
71
- }
72
- }
73
-
74
- // match the last html end tag of all content and all content before it
75
- const tagEndRegex = new RegExp ( `(.*)${ endTagRegexStr } ` , "i" ) ;
76
-
77
- for ( let i = 0 ; i < closeTagPoition ; i ++ ) {
78
- const tagCloseMatch = contentAfterTag . match ( tagEndRegex ) ;
79
- if ( tagCloseMatch ) {
80
- contentAfterTag = tagCloseMatch [ 1 ] ;
81
- }
82
- }
83
-
84
- const clearContentAfterCloseTagRegex = new RegExp ( `.*${ endTagRegexStr } ` , "i" ) ;
85
- const clearContentAfterCloseTagMatch = contentAfterTag . match (
86
- clearContentAfterCloseTagRegex ,
87
- ) ;
88
- if ( clearContentAfterCloseTagMatch ) {
89
- contentAfterTag = clearContentAfterCloseTagMatch [ 0 ] ;
90
- foundTagContents . push ( contentAfterTag ) ;
91
- }
92
-
93
- // replace the contentAfterTag in content with ""
94
- // only replace the first match
95
- const remainingHtmlRegex = new RegExp (
96
- contentAfterTag . replace ( / [ - \/ \\ ^ $ * + ? . ( ) | [ \] { } ] / g, "\\$&" ) + "(.*)" ,
97
- "i" ,
98
- ) ;
99
- const remainingHtmlMatch = content . match ( remainingHtmlRegex ) ;
100
- if ( remainingHtmlMatch ) {
101
- const remainingHtml = remainingHtmlMatch [ 1 ] ;
102
- // check if any html tag is left
103
- const remainingHtmlTagRegex = new RegExp ( `(<\\w+?>)` , "i" ) ;
104
- const remainingHtmlTagMatch = remainingHtml . match ( remainingHtmlTagRegex ) ;
105
- if ( remainingHtmlTagMatch ) {
106
- if ( maxDeep === - 1 || deep < maxDeep ) {
107
- return findHtmlTagContentsRecursive (
108
- remainingHtml ,
109
- targetTag ,
110
- targetClass ,
111
- foundTagContents ,
112
- deep + 1 ,
113
- maxDeep ,
114
- ) ;
115
- }
116
- log ( "warn" , "HTML search:" , "Max deep reached, recursive break" ) ;
117
- return foundTagContents ;
118
- }
119
- }
120
-
121
- return foundTagContents ;
122
- }
123
-
124
- /**
125
- * @deprecated
126
- */
127
- function findHtmlTagContents (
128
- content : string ,
129
- targetTag : string ,
130
- targetClass : string | null = null ,
131
- ) {
132
- return findHtmlTagContentsRecursive ( content , targetTag , targetClass ) ;
133
- }
134
-
135
- /**
136
- * @deprecated
137
- */
138
- function findHtmlTagContentsByClass ( content : string , targetClass : string ) {
139
- const regex = new RegExp (
140
- `(<(\\w+)\\s+class\\s*=\\s*['\"][^'\"]*?\\b${ targetClass } \\b)` ,
141
- "i" ,
142
- ) ;
143
- const match = content . match ( regex ) ;
144
- if ( match ) {
145
- const tag = match [ 2 ] ;
146
- return findHtmlTagContents ( content , tag , targetClass ) ;
147
- }
148
- return [ ] ;
149
- }
150
-
151
- function obfuscateHtmlClassNames ( {
9
+ export const obfuscateHtmlClassNames = ( {
152
10
html,
153
11
selectorConversion,
154
12
obfuscateMarkerClass = "" ,
@@ -158,7 +16,7 @@ function obfuscateHtmlClassNames({
158
16
selectorConversion : SelectorConversion ;
159
17
obfuscateMarkerClass ?: string ;
160
18
contentIgnoreRegexes ?: RegExp [ ] ;
161
- } ) {
19
+ } ) => {
162
20
const voidTags = [
163
21
"area" ,
164
22
"base" ,
@@ -295,9 +153,3 @@ function obfuscateHtmlClassNames({
295
153
usedKeys : Array . from ( new Set ( usedKeys ) ) ,
296
154
} ;
297
155
}
298
-
299
- export {
300
- findHtmlTagContents ,
301
- findHtmlTagContentsByClass ,
302
- obfuscateHtmlClassNames ,
303
- } ;
0 commit comments