Skip to content

Commit 35f4ca2

Browse files
committed
Pull request #11: feature: AG-4603 convert 1p,3p options
Merge in ADGUARD-IOS/safari-converter from feature/AG-4603 to master * commit '4910d61ac8fe5f91e20bd0c39241588dcac2ff5a': feature: AG-4603 convert 1p,3p options
2 parents 02d0cdd + 4910d61 commit 35f4ca2

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

Sources/ContentBlockerConverter/Rules/RuleConverter.swift

+5-1
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,16 @@ class RuleConverter {
287287
private static let ALL_OPTION = "all";
288288
private static let POPUP_OPTION = "popup";
289289
private static let DOCUMENT_OPTION = "document";
290+
private static let UBO_1P_OPTION = "1p";
291+
private static let UBO_3P_OPTION = "3p";
290292

291293
private static let conversionMap : [String:String] = [
292294
EMPTY_OPTION : "redirect=nooptext",
293295
MP4_OPTION : "redirect=noopmp4-1s",
294296
INLINE_SCRIPT_OPTION : CSP_OPTION + "=script-src 'self' 'unsafe-eval' http: https: data: blob: mediastream: filesystem:",
295-
INLINE_FONT_OPTION : CSP_OPTION + "=font-src 'self' 'unsafe-eval' http: https: data: blob: mediastream: filesystem:"
297+
INLINE_FONT_OPTION : CSP_OPTION + "=font-src 'self' 'unsafe-eval' http: https: data: blob: mediastream: filesystem:",
298+
UBO_1P_OPTION: "first-party",
299+
UBO_3P_OPTION: "third-party"
296300
]
297301

298302
private func convertOptions(rule: NSString) -> [NSString]? {

Tests/ContentBlockerConverterTests/Rules/RuleConverterTests.swift

+23
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,28 @@ final class RuleConverterTests: XCTestCase {
130130
XCTAssertEqual(res, [exp]);
131131
}
132132

133+
func testUboThirdPartyModifiers() {
134+
var exp = "||video.example.org^$third-party,match-case" as NSString;
135+
var res = ruleConverter.convertRule(rule: "||video.example.org^$3p,match-case" as NSString);
136+
XCTAssertEqual(res, [exp]);
137+
138+
exp = "||video.example.org^$match-case,third-party";
139+
res = ruleConverter.convertRule(rule: "||video.example.org^$match-case,3p" as NSString);
140+
XCTAssertEqual(res, [exp]);
141+
142+
exp = "||video.example.org^$first-party";
143+
res = ruleConverter.convertRule(rule: "||video.example.org^$1p" as NSString);
144+
XCTAssertEqual(res, [exp]);
145+
146+
exp = "||video.example.org^$first-party";
147+
res = ruleConverter.convertRule(rule: "||video.example.org^$first-party" as NSString);
148+
XCTAssertEqual(res, [exp]);
149+
150+
exp = "||video.example.org^$match-case,third-party,redirect=noopmp4-1s,media";
151+
res = ruleConverter.convertRule(rule: "||video.example.org^$match-case,3p,mp4" as NSString);
152+
XCTAssertEqual(res, [exp]);
153+
}
154+
133155
func testConvertUboScriptTags() {
134156
var exp = "example.com##^script:some-another-rule(test)" as NSString;
135157
var res = ruleConverter.convertRule(rule: "example.com##^script:some-another-rule(test)" as NSString);
@@ -237,6 +259,7 @@ final class RuleConverterTests: XCTestCase {
237259
("testConvertCssAGRules", testConvertCssAGRules),
238260
("testEmptyAndMp4Modifiers", testEmptyAndMp4Modifiers),
239261
("testMp4AndMediaModifiers", testMp4AndMediaModifiers),
262+
("testUboThirdPartyModifiers", testUboThirdPartyModifiers),
240263
("testConvertUboScriptTags", testConvertUboScriptTags),
241264
("testInlineScriptModifier", testInlineScriptModifier),
242265
("testInlineFontModifier", testInlineFontModifier),

0 commit comments

Comments
 (0)