-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from amco/45_improve_string_sanitizer
Use character set instead of regex for string sanitizer
- Loading branch information
Showing
9 changed files
with
138 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
Demo/librato-iOS DemoTests/NSString+ALMSanitizedForMetricTests.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// NSString+SanitizedForMetricTests.m | ||
// librato-iOS | ||
// | ||
// Created by Sergey Kuryanov on 20.10.16. | ||
// Copyright © 2016 Amco International Education Services, LLC. All rights reserved. | ||
// | ||
|
||
#import <XCTest/XCTest.h> | ||
#import "NSString+ALMSanitizedForMetric.h" | ||
|
||
@interface NSString_ALMSanitizedForMetricTests : XCTestCase | ||
@property (nonatomic, strong) NSString *testString; | ||
@end | ||
|
||
@implementation NSString_ALMSanitizedForMetricTests | ||
|
||
- (void)setUp { | ||
[super setUp]; | ||
|
||
self.testString = @"A-Za-z0-9.:-_<>{}[];\'\"!@#$%^&*()_+=œ∑´®†¥¨ˆøπ“‘«åß∂ƒ©˙∆˚¬…æΩ≈ç√∫˜µ≤≥÷"; | ||
} | ||
|
||
- (void)tearDown { | ||
self.testString = nil; | ||
|
||
[super tearDown]; | ||
} | ||
|
||
- (void)testThatOnlyAllowedCharactersPresent { | ||
NSString *expectedString = @"A-Za-z0-9.:-_-------------------_------------------------------------"; | ||
|
||
XCTAssertEqualObjects(self.testString.alm_sanitizedForMetric, expectedString); | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// NSString+ALMSanitizedForMetric.m | ||
// Librato-iOS | ||
// | ||
// Created by Adam Yanalunas on 10/3/13. | ||
// Copyright (c) 2013 Amco International Education Services, LLC. All rights reserved. | ||
// | ||
|
||
#import "NSString+ALMSanitizedForMetric.h" | ||
|
||
@implementation NSString (ALMSanitizedForMetric) | ||
|
||
- (NSString *)alm_sanitizedForMetric | ||
{ | ||
NSCharacterSet *allowedSet = [NSCharacterSet characterSetWithCharactersInString:@"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890.:-_"]; | ||
NSString *cleaned = [[self componentsSeparatedByCharactersInSet:allowedSet.invertedSet] componentsJoinedByString:@"-"]; | ||
return [cleaned substringToIndex:(self.length < 255 ? self.length : 255)]; | ||
} | ||
|
||
|
||
@end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters