| OLD | NEW |
| 1 /* ***** BEGIN LICENSE BLOCK ***** | 1 /* ***** BEGIN LICENSE BLOCK ***** |
| 2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
| 3 * | 3 * |
| 4 * The contents of this file are subject to the Mozilla Public License Version | 4 * The contents of this file are subject to the Mozilla Public License Version |
| 5 * 1.1 (the "License"); you may not use this file except in compliance with | 5 * 1.1 (the "License"); you may not use this file except in compliance with |
| 6 * the License. You may obtain a copy of the License at | 6 * the License. You may obtain a copy of the License at |
| 7 * http://www.mozilla.org/MPL/ | 7 * http://www.mozilla.org/MPL/ |
| 8 * | 8 * |
| 9 * Software distributed under the License is distributed on an "AS IS" basis, | 9 * Software distributed under the License is distributed on an "AS IS" basis, |
| 10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | 10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 * decision by deleting the provisions above and replace them with the notice | 32 * decision by deleting the provisions above and replace them with the notice |
| 33 * and other provisions required by the GPL or the LGPL. If you do not delete | 33 * and other provisions required by the GPL or the LGPL. If you do not delete |
| 34 * the provisions above, a recipient may use your version of this file under | 34 * the provisions above, a recipient may use your version of this file under |
| 35 * the terms of any one of the MPL, the GPL or the LGPL. | 35 * the terms of any one of the MPL, the GPL or the LGPL. |
| 36 * | 36 * |
| 37 * ***** END LICENSE BLOCK ***** */ | 37 * ***** END LICENSE BLOCK ***** */ |
| 38 | 38 |
| 39 #import <AppKit/AppKit.h> // for NSStringDrawing.h | 39 #import <AppKit/AppKit.h> // for NSStringDrawing.h |
| 40 | 40 |
| 41 #import "NSString+Utils.h" | 41 #import "NSString+Utils.h" |
| 42 #include "googleurl/src/gurl.h" |
| 42 | 43 |
| 43 | 44 |
| 44 @implementation NSString (ChimeraStringUtils) | 45 @implementation NSString (ChimeraStringUtils) |
| 45 | 46 |
| 46 + (id)ellipsisString | 47 + (id)ellipsisString |
| 47 { | 48 { |
| 48 static NSString* sEllipsisString = nil; | 49 static NSString* sEllipsisString = nil; |
| 49 if (!sEllipsisString) { | 50 if (!sEllipsisString) { |
| 50 unichar ellipsisChar = 0x2026; | 51 unichar ellipsisChar = 0x2026; |
| 51 sEllipsisString = [[NSString alloc] initWithCharacters:&ellipsisChar length:
1]; | 52 sEllipsisString = [[NSString alloc] initWithCharacters:&ellipsisChar length:
1]; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 82 return ([self hasCaseInsensitivePrefix:@"javascript:"] || [self hasCaseInsensi
tivePrefix:@"data:"]); | 83 return ([self hasCaseInsensitivePrefix:@"javascript:"] || [self hasCaseInsensi
tivePrefix:@"data:"]); |
| 83 } | 84 } |
| 84 | 85 |
| 85 - (BOOL)isPotentiallyDangerousURI | 86 - (BOOL)isPotentiallyDangerousURI |
| 86 { | 87 { |
| 87 return ([self hasCaseInsensitivePrefix:@"javascript:"] || [self hasCaseInsensi
tivePrefix:@"data:"]); | 88 return ([self hasCaseInsensitivePrefix:@"javascript:"] || [self hasCaseInsensi
tivePrefix:@"data:"]); |
| 88 } | 89 } |
| 89 | 90 |
| 90 - (BOOL)isValidURI | 91 - (BOOL)isValidURI |
| 91 { | 92 { |
| 92 // This will only return a non-nil object for valid, well-formed URI strings | 93 // isValid() will only be true for valid, well-formed URI strings |
| 93 NSURL* testURL = [NSURL URLWithString:self]; | 94 GURL testURL([self UTF8String]); |
| 94 | 95 |
| 95 // |javascript:| and |data:| URIs might not have passed the test, | 96 // |javascript:| and |data:| URIs might not have passed the test, |
| 96 // but spaces will work OK, so evaluate them separately. | 97 // but spaces will work OK, so evaluate them separately. |
| 97 if ((testURL) || [self isLooselyValidatedURI]) { | 98 if ((testURL.is_valid()) || [self isLooselyValidatedURI]) { |
| 98 return YES; | 99 return YES; |
| 99 } | 100 } |
| 100 return NO; | 101 return NO; |
| 101 } | 102 } |
| 102 | 103 |
| 103 - (NSString *)stringByRemovingCharactersInSet:(NSCharacterSet*)characterSet | 104 - (NSString *)stringByRemovingCharactersInSet:(NSCharacterSet*)characterSet |
| 104 { | 105 { |
| 105 NSScanner* cleanerScanner = [NSScanner scannerWithString:self]; | 106 NSScanner* cleanerScanner = [NSScanner scannerWithString:self]; |
| 106 NSMutableString* cleanString = [NSMutableString stringWithCapacity:[self le
ngth]]; | 107 NSMutableString* cleanString = [NSMutableString stringWithCapacity:[self le
ngth]]; |
| 107 // Make sure we don't skip whitespace, which NSScanner does by default | 108 // Make sure we don't skip whitespace, which NSScanner does by default |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 - (NSString*)unescapedURI | 354 - (NSString*)unescapedURI |
| 354 { | 355 { |
| 355 NSString *unescapedURI = (NSString*)CFURLCreateStringByReplacingPercentEscapes
UsingEncoding(kCFAllocatorDefault, | 356 NSString *unescapedURI = (NSString*)CFURLCreateStringByReplacingPercentEscapes
UsingEncoding(kCFAllocatorDefault, |
| 356 (CFS
tringRef)self, | 357 (CFS
tringRef)self, |
| 357 CFST
R(" \"\';/?:@&=+$,#"), | 358 CFST
R(" \"\';/?:@&=+$,#"), |
| 358 kCFS
tringEncodingUTF8); | 359 kCFS
tringEncodingUTF8); |
| 359 return unescapedURI ? [unescapedURI autorelease] : self; | 360 return unescapedURI ? [unescapedURI autorelease] : self; |
| 360 } | 361 } |
| 361 | 362 |
| 362 @end | 363 @end |
| OLD | NEW |