Permalink
Browse files

Commit

  • Loading branch information...
2 parents 11e883e + 97ca487 commit b3733c4687e34801481e64332d88b6a9779e92cc @Romes-- Romes-- committed Apr 23, 2014
Showing 483 changed files with 45,409 additions and 1 deletion.
View
@@ -16,6 +16,9 @@ xcuserdata
profile
*.moved-aside
DerivedData
+.idea/
*.hmap
*.ipa
+#CocoaPods
+Pods
View
@@ -0,0 +1,8 @@
+language: objective-c
+
+xcode_project: HTMLPurifier.xcodeproj
+xcode_scheme: HTMLPurifier
+
+##before_install: "git submodule init && git submodule update && sudo gem update --system && sudo gem install bundler && bundle install"
+
+##script: "bundle exec rake test --trace"
@@ -0,0 +1,33 @@
+//
+// HTMLPurifier_AttrDef_CSS.h
+// HTMLPurifier
+//
+// Created by Lukas Neumann on 13.01.14.
+
+
+
+/**
+ * Validates the HTML attribute style, otherwise known as CSS.
+ * @note We don't implement the whole CSS specification, so it might be
+ * difficult to reuse this component in the context of validating
+ * actual stylesheet declarations.
+ * @note If we were really serious about validating the CSS, we would
+ * tokenize the styles and then parse the tokens. Obviously, we
+ * are not doing that. Doing that could seriously harm performance,
+ * but would make these components a lot more viable for a CSS
+ * filtering solution.
+ */
+
+#import "HTMLPurifier_AttrDef.h"
+
+@interface HTMLPurifier_AttrDef_CSS : HTMLPurifier_AttrDef
+
+/**
+ * @param string $css
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return bool|string
+ */
+-(NSString*) validateWithString:(NSString *)css config:(HTMLPurifier_Config *)config context:(HTMLPurifier_Context *)context;
+
+@end
@@ -0,0 +1,139 @@
+//
+// HTMLPurifier_AttrDef_CSS.m
+// HTMLPurifier
+//
+// Created by Lukas Neumann on 13.01.14.
+
+
+/**
+ * Validates the HTML attribute style, otherwise known as CSS.
+ * @note We don't implement the whole CSS specification, so it might be
+ * difficult to reuse this component in the context of validating
+ * actual stylesheet declarations.
+ * @note If we were really serious about validating the CSS, we would
+ * tokenize the styles and then parse the tokens. Obviously, we
+ * are not doing that. Doing that could seriously harm performance,
+ * but would make these components a lot more viable for a CSS
+ * filtering solution.
+ */
+#import "BasicPHP.h"
+#import "HTMLPurifier_AttrDef_CSS.h"
+#import "HTMLPurifier_CSSDefinition.h"
+
+
+@implementation HTMLPurifier_AttrDef_CSS
+
+/**
+ * @param string $css
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return bool|string
+ */
+-(NSString*) validateWithString:(NSString *)css config:(HTMLPurifier_Config *)config context:(HTMLPurifier_Context *)context
+{
+ css = [super parseCDATAWithString:css];
+
+ HTMLPurifier_CSSDefinition* definition = [config getCSSDefinition];
+
+ // we're going to break the spec and explode by semicolons.
+ // This is because semicolon rarely appears in escaped form
+ // Doing this is generally flaky but fast
+ // IT MIGHT APPEAR IN URIs, see HTMLPurifier_AttrDef_CSSURI
+ // for details
+
+ NSArray* declarations = explode(@";",css);
+ NSMutableDictionary* propvalues = [NSMutableDictionary new];
+
+ //array of propvalue_keys (for preserving sort order)
+ NSMutableArray* propvalue_keys = [NSMutableArray new];
+ /**
+ * Name of the current CSS property being validated.
+ */
+ NSNumber* property = @(NO);
+ [context registerWithName:@"CurrentCSSProperty" ref:property];
+
+ for (NSString* declaration in declarations)
+ {
+ if (declaration.length==0)
+ {
+ continue;
+ }
+ if (!strpos(declaration, @":"))
+ {
+ continue;
+ }
+
+
+ //list(property, $value) = explode(':', $declaration, 2);
+ NSArray* temp = explodeWithLimit(@":",declaration,2);
+ NSString* property_string = nil;
+ if(temp.count>0)
+ property_string = [temp objectAtIndex:0];
+ else
+ continue;
+ NSString* value = nil;
+ if(temp.count>1)
+ value = [temp objectAtIndex:1];
+ else
+ continue;
+
+ property_string = trim(property_string);
+ value = trim(value);
+
+ NSNumber* ok = @(NO);
+ do {
+ if ([definition info][property_string])
+ {
+ ok = @(YES);
+ break;
+ }
+ property_string = [property_string lowercaseString];
+ if ([definition info][property_string])
+ {
+ ok = @(YES);
+ break;
+ }
+ } while (0);
+ if (![ok boolValue]) {
+ continue;
+ }
+ // inefficient call, since the validator will do this again
+ NSString* result;
+ // inefficient call, since the validator will do this again
+ if (![[value lowercaseString] isEqual:@"inherit"])
+ {
+ // inherit works for everything (but only on the base property)
+ HTMLPurifier_AttrDef* attrDef = definition.info[property_string];
+ result = [attrDef validateWithString:value config:config context:context];
+ }
+ else
+ {
+ result = @"inherit";
+ }
+ if (!result)
+ {
+ continue;
+ }
+ if([propvalue_keys containsObject:property_string])
+ [propvalue_keys removeObject:property_string];
+ propvalues[property_string] = result;
+ [propvalue_keys addObject:property_string];
+ }
+
+ [context destroy:@"CurrentCSSProperty"];
+
+ // procedure does not write the new CSS simultaneously, so it's
+ // slightly inefficient, but it's the only way of getting rid of
+ // duplicates. Perhaps config to optimize it, but not now.
+
+ NSString* new_declarations = @"";
+ for (NSString* key in propvalue_keys)
+ {
+ new_declarations = [new_declarations stringByAppendingString:[NSString stringWithFormat:@"%@:%@;",key,propvalues[key]]];
+ }
+
+ return [new_declarations isEqual:@""] ? nil : new_declarations;
+
+}
+
+@end
@@ -0,0 +1,15 @@
+//
+// HTMLPurifier_AttrDef_CSS_AlphaValue.h
+// HTMLPurifier
+//
+// Created by Roman Priebe on 11.01.14.
+
+
+#import "HTMLPurifier_AttrDef_CSS_Number.h"
+
+@interface HTMLPurifier_AttrDef_CSS_AlphaValue : HTMLPurifier_AttrDef_CSS_Number
+
+- (NSString*)validateWithString:(NSString *)string config:(HTMLPurifier_Config *)config context:(HTMLPurifier_Context *)context;
+
+
+@end
@@ -0,0 +1,45 @@
+//
+// HTMLPurifier_AttrDef_CSS_AlphaValue.m
+// HTMLPurifier
+//
+// Created by Roman Priebe on 11.01.14.
+
+
+#import "HTMLPurifier_AttrDef_CSS_AlphaValue.h"
+
+@implementation HTMLPurifier_AttrDef_CSS_AlphaValue
+
+- (id)init
+{
+ self = [super initWithNonNegative:NO]; // opacity is non-negative, but we will clamp it
+
+ if (self) {
+
+ }
+ return self;
+}
+
+/**
+ * @param string $number
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return string
+ */
+- (NSString*)validateWithString:(NSString *)string config:(HTMLPurifier_Config *)config context:(HTMLPurifier_Context *)context
+ {
+ NSString* result = [super validateWithString:string config:config context:context];
+ if (!result) {
+ return nil;
+ }
+ float floatResult = result.floatValue;
+ if (floatResult < 0.0) {
+ result = @"0";
+ }
+ if (floatResult > 1.0) {
+ result = @"1";
+ }
+ return result;
+ }
+
+
+@end
@@ -0,0 +1,41 @@
+//
+// HTMLPurifier_AttrDef_CSS_Background.h
+// HTMLPurifier
+//
+// Created by Roman Priebe on 11.01.14.
+
+
+#import "HTMLPurifier_AttrDef.h"
+
+@class HTMLPurifier_Config;
+
+/**
+ * Validates shorthand CSS property background.
+ * @warning Does not support url tokens that have internal spaces.
+ */
+@interface HTMLPurifier_AttrDef_CSS_Background : HTMLPurifier_AttrDef
+{
+
+ /**
+ * Local copy of component validators.
+ * @type HTMLPurifier_AttrDef[]
+ * @note See HTMLPurifier_AttrDef_Font::$info for a similar impl.
+ */
+ NSMutableDictionary* info;
+}
+ /**
+ * @param HTMLPurifier_Config $config
+ */
+- (id)initWithConfig:(HTMLPurifier_Config*)config;
+
+
+ /**
+ * @param string $string
+ * @param HTMLPurifier_Config $config
+ * @param HTMLPurifier_Context $context
+ * @return bool|string
+ */
+- (NSString*)validateWithString:(NSString *)someString config:(HTMLPurifier_Config *)config context:(HTMLPurifier_Context *)context;
+
+
+@end
Oops, something went wrong.

0 comments on commit b3733c4

Please sign in to comment.