Commits

dcutting committed 33e1048

Handle whitespace URLs.

  • Participants
  • Parent commits 36afd7f

Comments (0)

Files changed (4)

File VeriJSON.xcodeproj/project.pbxproj

 		C8A2072D169584C8001CA314 /* ObjectWithURLPattern.json in Resources */ = {isa = PBXBuildFile; fileRef = C8A2072B169584C8001CA314 /* ObjectWithURLPattern.json */; };
 		C8A2073016958593001CA314 /* ObjectWithURLInvalid.json in Resources */ = {isa = PBXBuildFile; fileRef = C8A2072F16958593001CA314 /* ObjectWithURLInvalid.json */; };
 		C8A20732169585CC001CA314 /* ObjectWithURLInvalidEmpty.json in Resources */ = {isa = PBXBuildFile; fileRef = C8A20731169585CC001CA314 /* ObjectWithURLInvalidEmpty.json */; };
+		C8A20734169586B1001CA314 /* ObjectWithURLInvalidWhitespace.json in Resources */ = {isa = PBXBuildFile; fileRef = C8A20733169586B1001CA314 /* ObjectWithURLInvalidWhitespace.json */; };
 		C8A64F6F1692647700D01705 /* SimpleArray.json in Resources */ = {isa = PBXBuildFile; fileRef = C8A64F6E1692647700D01705 /* SimpleArray.json */; };
 		C8A64F721692648B00D01705 /* SimpleArrayPattern.json in Resources */ = {isa = PBXBuildFile; fileRef = C8A64F711692648B00D01705 /* SimpleArrayPattern.json */; };
 		C8A64F761692654800D01705 /* ArrayOfStringsPattern.json in Resources */ = {isa = PBXBuildFile; fileRef = C8A64F741692654800D01705 /* ArrayOfStringsPattern.json */; };
 		C8A2072B169584C8001CA314 /* ObjectWithURLPattern.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = ObjectWithURLPattern.json; path = Data/ObjectWithURLPattern.json; sourceTree = "<group>"; };
 		C8A2072F16958593001CA314 /* ObjectWithURLInvalid.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = ObjectWithURLInvalid.json; path = Data/ObjectWithURLInvalid.json; sourceTree = "<group>"; };
 		C8A20731169585CC001CA314 /* ObjectWithURLInvalidEmpty.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = ObjectWithURLInvalidEmpty.json; path = Data/ObjectWithURLInvalidEmpty.json; sourceTree = "<group>"; };
+		C8A20733169586B1001CA314 /* ObjectWithURLInvalidWhitespace.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = ObjectWithURLInvalidWhitespace.json; path = Data/ObjectWithURLInvalidWhitespace.json; sourceTree = "<group>"; };
 		C8A64F6E1692647700D01705 /* SimpleArray.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = SimpleArray.json; path = Data/SimpleArray.json; sourceTree = "<group>"; };
 		C8A64F711692648B00D01705 /* SimpleArrayPattern.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = SimpleArrayPattern.json; path = Data/SimpleArrayPattern.json; sourceTree = "<group>"; };
 		C8A64F741692654800D01705 /* ArrayOfStringsPattern.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = ArrayOfStringsPattern.json; path = Data/ArrayOfStringsPattern.json; sourceTree = "<group>"; };
 				C8A2072A169584C8001CA314 /* ObjectWithURL.json */,
 				C8A2072F16958593001CA314 /* ObjectWithURLInvalid.json */,
 				C8A20731169585CC001CA314 /* ObjectWithURLInvalidEmpty.json */,
+				C8A20733169586B1001CA314 /* ObjectWithURLInvalidWhitespace.json */,
 			);
 			name = Data;
 			sourceTree = "<group>";
 				C8A2072D169584C8001CA314 /* ObjectWithURLPattern.json in Resources */,
 				C8A2073016958593001CA314 /* ObjectWithURLInvalid.json in Resources */,
 				C8A20732169585CC001CA314 /* ObjectWithURLInvalidEmpty.json in Resources */,
+				C8A20734169586B1001CA314 /* ObjectWithURLInvalidWhitespace.json in Resources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

File VeriJSON/VeriJSON/VeriJSON.m

 }
 
 - (BOOL)verifyURL:(NSString *)value {
-    if (0 == [value length]) return NO;
+    NSString *trimmedValue = [value stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
+    if (0 == [trimmedValue length]) return NO;
     NSURL *url = [NSURL URLWithString:value];
     return nil != url;
 }

File VeriJSONTests/Data/ObjectWithURLInvalidWhitespace.json

+{
+    "self": " "
+}

File VeriJSONTests/VeriJSONTests.m

             BOOL valid = [veriJSON verifyJSON:json pattern:pattern];
             [[@(valid) should] beNo];
         });
+        
+        it(@"whitespace URL", ^{
+            id json = [bundle jsonFromResource:@"ObjectWithURLInvalidWhitespace.json"];
+            BOOL valid = [veriJSON verifyJSON:json pattern:pattern];
+            [[@(valid) should] beNo];
+        });
     });
     
     it(@"hack to ensure tests finish", ^{