mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-10-11 23:07:12 +00:00
feat(core): Add message of the day. Remove all html tags except for anchor tags (mobile only)
This commit is contained in:
1 parent
f43974bbb7
commit
455fe97cbe
4 files changed
+29
-1
No files matched your search
@@ -76,6 +76,8 @@
|
||||
/* OpenSSL multiline DN */
|
||||
- (NSArray *) componentsFromMultilineDN;
|
||||
|
||||
/* XSS protection */
|
||||
- (NSString *) removeHTMLTagsExceptAnchorTags;
|
||||
- (NSString *) stringWithoutHTMLInjection: (BOOL)stripHTMLCode;
|
||||
|
||||
#ifndef GNUSTEP_BASE_LIBRARY
|
||||
|
||||
@@ -903,6 +903,28 @@ static int cssEscapingCount;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all HTML tags except for <a> </a>
|
||||
* @return A clean string
|
||||
*/
|
||||
- (NSString *)removeHTMLTagsExceptAnchorTags {
|
||||
NSError *error;
|
||||
NSRegularExpression *regex;
|
||||
NSString *stringWithoutHTML;
|
||||
|
||||
error = nil;
|
||||
|
||||
regex = [NSRegularExpression regularExpressionWithPattern: @"<(?!a|\\/a\\b)[^>]*>" options: NSRegularExpressionCaseInsensitive error: &error];
|
||||
stringWithoutHTML = [regex stringByReplacingMatchesInString: self options: 0 range: NSMakeRange(0, [self length]) withTemplate:@""];
|
||||
|
||||
if (error) {
|
||||
[self logWithFormat: @"Error while removing tags : %@", [error localizedDescription]];
|
||||
return self;
|
||||
}
|
||||
|
||||
return stringWithoutHTML;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the safe string avoiding HTML injection
|
||||
* @param stripHTMLCode Remove all HTML code from content
|
||||
|
||||
Reference in new issue
Block a user