mirror of
https://github.com/gkd-kit/gkd.git
synced 2024-11-15 19:22:26 +08:00
fix(selector): not throw StringIndexOut in js
https://github.com/gkd-kit/inspect/issues/7 修复在 js 里 string[i] 不会抛 StringIndexOutOfBoundsException 导致无限循环申请内存最终内存溢出
This commit is contained in:
parent
30a6f59468
commit
aa706b9fd5
|
@ -1,8 +0,0 @@
|
|||
package li.songe.selector
|
||||
|
||||
import kotlin.js.ExperimentalJsExport
|
||||
import kotlin.js.JsExport
|
||||
|
||||
@OptIn(ExperimentalJsExport::class)
|
||||
@JsExport
|
||||
const val version = "0.0.6"
|
|
@ -198,9 +198,12 @@ internal object ParserSet {
|
|||
ExtSyntaxError.assert(source, i, prefix)
|
||||
val startChar = source[i]
|
||||
i++
|
||||
if (i >= source.length) {
|
||||
ExtSyntaxError.throwError(source, i, "any char")
|
||||
}
|
||||
var data = ""
|
||||
while (source[i] != startChar) {
|
||||
if (i == source.length - 1) {
|
||||
if (i >= source.length - 1) {
|
||||
ExtSyntaxError.assert(source, i, startChar.toString())
|
||||
break
|
||||
}
|
||||
|
@ -442,7 +445,10 @@ internal object ParserSet {
|
|||
val selectorList = mutableListOf<Pair<ConnectSegment, PropertySegment>>()
|
||||
while (i < source.length && whiteCharParser.prefix.contains(source[i])) {
|
||||
i += whiteCharStrictParser(source, i).length
|
||||
val combinator = if (combinatorParser.prefix.contains((source[i]))) {
|
||||
if (i >= source.length) {
|
||||
break
|
||||
}
|
||||
val combinator = if (combinatorParser.prefix.contains(source[i])) {
|
||||
val combinatorResult = combinatorParser(source, i)
|
||||
i += combinatorResult.length
|
||||
i += whiteCharStrictParser(source, i).length
|
||||
|
|
|
@ -72,10 +72,9 @@ class ParserTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun check_query(){
|
||||
fun check_query() {
|
||||
val projectCwd = File("../").absolutePath
|
||||
val text =
|
||||
"@TextView[text^='跳过'] + LinearLayout TextView[text*=`跳转`]"
|
||||
val text = "@TextView[text^='跳过'] + LinearLayout TextView[text*=`跳转`]"
|
||||
val selector = Selector.parse(text)
|
||||
println("selector: $selector")
|
||||
println(selector.trackIndex)
|
||||
|
@ -94,8 +93,8 @@ class ParserTest {
|
|||
}
|
||||
}
|
||||
val transform = Transform<TestNode>(getAttr = { node, name ->
|
||||
if (name=="_id") return@Transform node.id
|
||||
if (name=="_pid") return@Transform node.pid
|
||||
if (name == "_id") return@Transform node.id
|
||||
if (name == "_pid") return@Transform node.pid
|
||||
val value = node.attr[name] ?: return@Transform null
|
||||
if (value is JsonNull) return@Transform null
|
||||
value.intOrNull ?: value.booleanOrNull ?: value.content
|
||||
|
@ -106,4 +105,11 @@ class ParserTest {
|
|||
println("target_size: " + targets.size)
|
||||
println(targets.firstOrNull())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun check_quote() {
|
||||
// https://github.com/gkd-kit/inspect/issues/7
|
||||
val selector = Selector.parse("a[a=''] ")
|
||||
println("check_quote:$selector")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user