Skip to content

Commit 08d7a1d

Browse files
committed
Progress commit (save)
1 parent 429d8f7 commit 08d7a1d

File tree

8 files changed

+97
-7
lines changed

8 files changed

+97
-7
lines changed

SCUtils.h

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// SCUtils.h
3+
//
4+
//
5+
// Created by Charles Stigler on 08/05/2017.
6+
//
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
@interface SCUtils : NSObject
12+
13+
@end

SCUtils.m

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//
2+
// SCUtils.m
3+
//
4+
//
5+
// Created by Charles Stigler on 08/05/2017.
6+
//
7+
//
8+
9+
#import "SCUtils.h"
10+
11+
@implementation SCUtils
12+
13+
- (NSString*)stringWithoutRegexSpecialChars:(NSString*)input {
14+
return [input stringByReplacingOccurrencesOfString: @"[\\\\\\^\\$\\.\\|\\?\\*\\+\\(\\)\\[\\{]"
15+
withString: @"\\\\$0"
16+
options: NSRegularExpressionSearch
17+
range: (NSRange){0, [input length]}];
18+
// return [input stringByR (of: "[\\\\\\^\\$\\.\\|\\?\\*\\+\\(\\)\\[\\{]",
19+
// with: "\\\\$0",
20+
// options: .regularExpression)
21+
}
22+
23+
@end

SelfControlIOS.xcodeproj/project.pbxproj

+10
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
A339774405143C9F31B34DA3 /* Pods_SelfControlIOSTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2E38E2A3851FB26B638BC57F /* Pods_SelfControlIOSTests.framework */; };
1313
A7004475EED8281FC7E23E31 /* Pods_SCFilterControlProvider.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4FEDDAF9959688D12A1484F5 /* Pods_SCFilterControlProvider.framework */; };
1414
C415A43D29B9C5251812EF9B /* Pods_SelfControlIOSUITests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 40D1DD9B7ABFD420591B5C45 /* Pods_SelfControlIOSUITests.framework */; };
15+
CB0E6AA11EC19759003CA02B /* SCUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = CB0E6AA01EC19759003CA02B /* SCUtils.m */; };
16+
CB0E6AA21EC1982A003CA02B /* SCUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = CB0E6AA01EC19759003CA02B /* SCUtils.m */; };
17+
CB0E6AA31EC1982A003CA02B /* SCUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = CB0E6AA01EC19759003CA02B /* SCUtils.m */; };
1518
CB84E2EA1E109803005A0A6B /* SCFilterDataProvider.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = CB84E2E11E109803005A0A6B /* SCFilterDataProvider.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
1619
CB84E2FB1E1098E6005A0A6B /* SCFilterControlProvider.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = CB84E2F21E1098E6005A0A6B /* SCFilterControlProvider.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
1720
CB84E3081E109A59005A0A6B /* DataExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB84E3051E109A59005A0A6B /* DataExtension.swift */; };
@@ -104,6 +107,8 @@
104107
C21782EE3B920946130B3C63 /* Pods-SCFilterControlProvider.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SCFilterControlProvider.release.xcconfig"; path = "Pods/Target Support Files/Pods-SCFilterControlProvider/Pods-SCFilterControlProvider.release.xcconfig"; sourceTree = "<group>"; };
105108
C71BD1CBC762FFF03C7DF4E8 /* Pods-SCFilterDataProvider.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SCFilterDataProvider.release.xcconfig"; path = "Pods/Target Support Files/Pods-SCFilterDataProvider/Pods-SCFilterDataProvider.release.xcconfig"; sourceTree = "<group>"; };
106109
CB0A04121E9B556B00EDD04F /* SelfControlIOS.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = SelfControlIOS.entitlements; sourceTree = "<group>"; };
110+
CB0E6A9F1EC19759003CA02B /* SCUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SCUtils.h; sourceTree = "<group>"; };
111+
CB0E6AA01EC19759003CA02B /* SCUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SCUtils.m; sourceTree = "<group>"; };
107112
CB5D28AC1E9B572600EF7753 /* SCFilterDataProvider.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = SCFilterDataProvider.entitlements; sourceTree = "<group>"; };
108113
CB5D28AD1E9B572D00EF7753 /* SCFilterControlProvider.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = SCFilterControlProvider.entitlements; sourceTree = "<group>"; };
109114
CB84E2E11E109803005A0A6B /* SCFilterDataProvider.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = SCFilterDataProvider.appex; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -291,6 +296,8 @@
291296
CBF188DF1E62AC83008EFB00 /* SCBlockRule.m */,
292297
CBF188DB1E62AAB4008EFB00 /* SCBlockManager.h */,
293298
CBF188DC1E62AAB4008EFB00 /* SCBlockManager.m */,
299+
CB0E6A9F1EC19759003CA02B /* SCUtils.h */,
300+
CB0E6AA01EC19759003CA02B /* SCUtils.m */,
294301
CB93D1B01E0F216700CE0571 /* Main.storyboard */,
295302
CB93D1B31E0F216700CE0571 /* Assets.xcassets */,
296303
CB93D1B51E0F216700CE0571 /* LaunchScreen.storyboard */,
@@ -752,6 +759,7 @@
752759
CB84E3131E10AAB6005A0A6B /* FilterUtilities.swift in Sources */,
753760
CBF188E11E62AEAF008EFB00 /* SCBlockRule.m in Sources */,
754761
CB84E3081E109A59005A0A6B /* DataExtension.swift in Sources */,
762+
CB0E6AA21EC1982A003CA02B /* SCUtils.m in Sources */,
755763
);
756764
runOnlyForDeploymentPostprocessing = 0;
757765
};
@@ -762,6 +770,7 @@
762770
CB84E3141E10AAB7005A0A6B /* FilterUtilities.swift in Sources */,
763771
CBF188E21E62AEB0008EFB00 /* SCBlockRule.m in Sources */,
764772
CB84E30F1E109AB5005A0A6B /* ControlExtension.swift in Sources */,
773+
CB0E6AA31EC1982A003CA02B /* SCUtils.m in Sources */,
765774
);
766775
runOnlyForDeploymentPostprocessing = 0;
767776
};
@@ -778,6 +787,7 @@
778787
CB93D1AD1E0F216700CE0571 /* BlockViewController.swift in Sources */,
779788
CBF188CB1E6299F0008EFB00 /* main.m in Sources */,
780789
CBF188DA1E629D16008EFB00 /* SCMainViewController.m in Sources */,
790+
CB0E6AA11EC19759003CA02B /* SCUtils.m in Sources */,
781791
CBF188CE1E629A3B008EFB00 /* SCAppDelegate.m in Sources */,
782792
CBF188D11E629B5A008EFB00 /* SCStartViewController.m in Sources */,
783793
CBF188DD1E62AAB4008EFB00 /* SCBlockManager.m in Sources */,

SelfControlIOS.xcworkspace/contents.xcworkspacedata

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SelfControlIOS/FilterUtilities.swift

+6-7
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,17 @@ open class FilterUtilities: NSObject {
9090

9191
// first remove the *. prefix
9292
var regexRule = rule.key.substring(from: rule.key.index(rule.key.startIndex, offsetBy: 2))
93-
NSLog("unprefixed: \(regexRule)")
9493

9594
// next remove all other regex special characters
9695
// (they usually shouldn't be in hostnames anyway
9796
// TODO: escape them and leave them in the regex
98-
regexRule = regexRule.replacingOccurrences(of: "\\\\\\^\\$\\.\\|\\?\\*\\+\\(\\)\\[\\{",
99-
with: "\\$0",
100-
options: .regularExpression)
101-
NSLog("special chars removed: \(regexRule)")
97+
regexRule = SCUtils.stringWithoutRegexSpecialChars(regexRule)
10298

10399
// and re-add the wildcard subdomain part properly
104-
regexRule = ".*\\.\(regexRule)";
100+
// wildcards for us match the root domain also, because it's
101+
// what average-Jane user would normally expect (yes, I know it's
102+
// inconsistent with some other uses)
103+
regexRule = ".*\\.?\(regexRule)$";
105104

106105
// finally, run it against hostname (make sure to make it work on the root domain also)
107106
NSLog("Treating as a wildcard rule, regex: \(regexRule)")
@@ -128,7 +127,7 @@ open class FilterUtilities: NSObject {
128127
NSLog("*** Block is over! Removing object")
129128
defaults?.removeObject(forKey: "blockEndDate")
130129
} else { NSLog("Allow all, no block.") }
131-
return (.allow, hostname, [:])
130+
return (.allow, hostname, [: ])
132131
}
133132

134133
guard !hostname.isEmpty else { return (.allow, hostname, [:]) }

SelfControlIOS/SCUtils.h

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// SCUtils.h
3+
//
4+
//
5+
// Created by Charles Stigler on 08/05/2017.
6+
//
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
@interface SCUtils : NSObject
12+
13+
+ (NSString*)stringWithoutRegexSpecialChars:(NSString*)input;
14+
15+
@end

SelfControlIOS/SCUtils.m

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//
2+
// SCUtils.m
3+
//
4+
//
5+
// Created by Charles Stigler on 08/05/2017.
6+
//
7+
//
8+
9+
#import "SCUtils.h"
10+
11+
@implementation SCUtils
12+
13+
+ (NSString*)stringWithoutRegexSpecialChars:(NSString*)input {
14+
return [input stringByReplacingOccurrencesOfString: @"[\\\\\\^\\$\\.\\|\\?\\*\\+\\(\\)\\[\\{]"
15+
withString: @"\\\\$0"
16+
options: NSRegularExpressionSearch
17+
range: (NSRange){0, [input length]}];
18+
// return [input stringByR (of: "[\\\\\\^\\$\\.\\|\\?\\*\\+\\(\\)\\[\\{]",
19+
// with: "\\\\$0",
20+
// options: .regularExpression)
21+
}
22+
23+
@end

SelfControlIOS/SelfControlIOS-Bridging-Header.h

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
//
44

55
#import "SCBlockRule.h"
6+
#import "SCUtils.h"

0 commit comments

Comments
 (0)