Skip to content

Commit eb6ed74

Browse files
author
codersdg
committed
添加正则校验
修改Rule名称回调时机
1 parent b74a56e commit eb6ed74

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

NIO1901/Modules/RuleList/Controller/RuleOverViewController.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ class RuleItemView: UIView {
257257
contentField?.tag = 0
258258
contentField?.delegate = self
259259
contentView.addSubview(contentField!)
260+
contentField?.addTarget(self, action: #selector(textFieldDidChange(_:)), for: UIControl.Event.editingChanged)
260261
break
261262
case .Switch:
262263
let labelFrame = CGRect(x: LRSpacing, y: 0, width: SCREENWIDTH - LRSpacing * 2 - 50, height: contentHeight)
@@ -297,10 +298,13 @@ class RuleItemView: UIView {
297298
@objc func contentViewDidClick(){
298299
contentDidClickHandle?()
299300
}
301+
302+
@objc func textFieldDidChange(_ textField: UITextField) {
303+
textValueChangeHandle?(textField.text ?? "")
304+
305+
}
300306
}
301307

302308
extension RuleItemView: UITextFieldDelegate {
303-
func textFieldDidEndEditing(_ textField: UITextField) {
304-
textValueChangeHandle?(textField.text ?? "")
305-
}
309+
306310
}

TunnelServices/Rule/Rule.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,10 @@ public class Rule: ASModel {
450450
case .DOMAINSUFFIX:
451451
if host.lowercased().hasSuffix(item.value.lowercased()) { return true }
452452
case .URLREGEX:
453+
guard (try? NSRegularExpression(pattern: item.value, options: .caseInsensitive)) != nil else {
454+
print("Invalid Regex")
455+
return false
456+
}
453457
let pred = NSPredicate(format: "SELF MATCHES %@", item.value)
454458
if pred.evaluate(with: host) || pred.evaluate(with: fullUri) || pred.evaluate(with: fullUri.urlEncoded()) {
455459
return true
@@ -497,6 +501,10 @@ public class Rule: ASModel {
497501
// print("命中DOMAINSUFFIX(\(item.value)):\n*************************\n\(host)\n\(target)\n\(uri)\n*************************")
498502
return true }
499503
case .URLREGEX:
504+
guard (try? NSRegularExpression(pattern: item.value, options: .caseInsensitive)) != nil else {
505+
print("Invalid Regex")
506+
return false
507+
}
500508
let pred = NSPredicate(format: "SELF MATCHES %@", item.value)
501509
if pred.evaluate(with: host) || pred.evaluate(with: fullUri) || pred.evaluate(with: fullUri.urlEncoded()) {
502510
// print("命中URLREGEX(\(item.value)):\n*************************\n\(host)\n\(target)\n\(uri)\n*************************")

0 commit comments

Comments
 (0)