Skip to content
This repository was archived by the owner on Dec 13, 2017. It is now read-only.

Commit abdc279

Browse files
authored
Merge pull request #891 from wordpress-mobile/issue/sanitize-content
Added checks for delegate methods and updated doc comments
2 parents 6dea9f0 + 042ee1a commit abdc279

9 files changed

Lines changed: 92 additions & 47 deletions

Classes/HRColorPickerViewController.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,10 @@ typedef enum {
6666
*/
6767
- (id)initWithColor:(UIColor*)defaultColor fullColor:(BOOL)fullColor saveStyle:(HCPCSaveStyle)saveStyle;
6868

69-
/** @deprecated use -save: instead of this . */
70-
- (void)saveColor:(id)sender;
69+
/**
70+
* @deprecated use -save: instead of this.
71+
*/
72+
- (void)saveColor:(id)sender __attribute__((deprecated));
7173

7274
- (void)save;
7375
- (void)save:(id)sender;

Classes/WPEditorField.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* @brief Initializes the field with the specified HTML node id.
1919
*
2020
* @param nodeId The id of the html node this object will wrap. Cannot be nil.
21-
* @param webVieq The web view to use for all javascript calls. Cannot be nil.
21+
* @param webView The web view to use for all javascript calls. Cannot be nil.
2222
*
2323
* @returns The initialized object.
2424
*/
@@ -87,7 +87,7 @@
8787
/**
8888
* @brief Sets the placeholder color for this field.
8989
*
90-
* @param placeholderText The new placeholder color.
90+
* @param placeholderColor The new placeholder color.
9191
*/
9292
- (void)setPlaceholderColor:(UIColor *)placeholderColor;
9393

Classes/WPEditorField.m

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ - (void)setText:(NSString*)text
169169
} else {
170170

171171
if (text) {
172-
text = [self addSlashes:text];
172+
text = [self sanitizeHTML:text];
173173
} else {
174174
text = @"";
175175
}
@@ -187,7 +187,7 @@ - (void)setHtml:(NSString*)html
187187
} else {
188188

189189
if (html) {
190-
html = [self addSlashes:html];
190+
html = [self sanitizeHTML:html];
191191
} else {
192192
html = @"";
193193
}
@@ -205,7 +205,7 @@ - (void)setPlaceholderText:(NSString*)placeholderText
205205
if (!self.domLoaded) {
206206
self.preloadedPlaceholderText = placeholderText;
207207
} else {
208-
placeholderText = [self addSlashes:placeholderText];
208+
placeholderText = [self sanitizeHTML:placeholderText];
209209
NSString* javascript = [NSString stringWithFormat:@"%@.setPlaceholderText(\"%@\");", [self wrappedNodeJavascriptAccessor], placeholderText];
210210

211211
[self.webView stringByEvaluatingJavaScriptFromString:javascript];
@@ -232,14 +232,14 @@ - (void)setPlaceholderColor:(UIColor *)placeholderColor
232232
#pragma mark - URL & HTML utilities
233233

234234
/**
235-
* @brief Adds slashes to the specified HTML string, to prevent injections when calling JS
235+
* @brief Adds slashes and removes script tags from the specified HTML string, to prevent injections when calling JS
236236
* code.
237237
*
238-
* @param html The HTML string to add slashes to. Cannot be nil.
238+
* @param html The HTML string to sanitize. Cannot be nil.
239239
*
240-
* @returns The HTML string with the added slashes.
240+
* @returns The sanitized HTML string.
241241
*/
242-
- (NSString *)addSlashes:(NSString *)html
242+
- (NSString *)sanitizeHTML:(NSString *)html
243243
{
244244
html = [html stringByReplacingOccurrencesOfString:@"\\" withString:@"\\\\"];
245245
html = [html stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""];
@@ -252,6 +252,9 @@ - (NSString *)addSlashes:(NSString *)html
252252
html = [html stringByReplacingOccurrencesOfString:@"\u2028" withString:@"\\u2028"];
253253
html = [html stringByReplacingOccurrencesOfString:@"\u2029" withString:@"\\u2029"];
254254

255+
html = [html stringByReplacingOccurrencesOfString:@"<script>" withString:@"&lt;script&gt;" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [html length])];
256+
html = [html stringByReplacingOccurrencesOfString:@"</script>" withString:@"&lt;/script&gt;" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [html length])];
257+
255258
return html;
256259
}
257260

Classes/WPEditorView.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
* @brief Received when the user taps on a video in the editor.
125125
*
126126
* @param editorView The editor view.
127-
* @param videoId The id of image of the image that was tapped.
127+
* @param videoID The id of image of the image that was tapped.
128128
* @param url The url of the image that was tapped.
129129
*
130130
*/
@@ -156,7 +156,7 @@ stylesForCurrentSelection:(NSArray*)styles;
156156
* @brief Received when a video local url is replaced by the final remote url.
157157
*
158158
* @param editorView The editor view.
159-
* @param videoId The unique id of the video that had the local url replaced by remote url.
159+
* @param videoID The unique id of the video that had the local url replaced by remote url.
160160
*
161161
*/
162162
- (void)editorView:(WPEditorView*)editorView
@@ -166,7 +166,7 @@ stylesForCurrentSelection:(NSArray*)styles;
166166
* @brief Received when an image is pasted into the editor.
167167
*
168168
* @param editorView The editor view.
169-
* @param imageId The id of image of the image that was pasted.
169+
* @param image The image that was pasted.
170170
*
171171
*/
172172
- (void)editorView:(WPEditorView*)editorView

Classes/WPEditorView.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ - (void)handleVideoTappedCallback:(NSURL *)url
680680
/**
681681
* @brief Handles a video entered fullscreen callback
682682
*
683-
* @param url The url with all the callback information.
683+
* @param aURL The url with all the callback information.
684684
*/
685685
- (void)handleVideoFullScreenStartedCallback:(NSURL *)aURL
686686
{
@@ -717,7 +717,7 @@ - (UIView *)findFirstResponder:(UIView *)currentView
717717
/**
718718
* @brief Handles a video ended fullscreen callback.
719719
*
720-
* @param url The url with all the callback information.
720+
* @param aURL The url with all the callback information.
721721
*/
722722
- (void)handleVideoFullScreenEndedCallback:(NSURL *)aURL
723723
{

Classes/WPEditorViewController.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ WPEditorViewControllerMode;
3131
/**
3232
* @brief Received when the format bar enabled status has changed.
3333
* @param editorController The editor view.
34-
* @param enabled BOOL describing the new state of the format bar
34+
* @param isEnabled BOOL describing the new state of the format bar
3535
*/
3636
- (void)editorFormatBarStatusChanged:(WPEditorViewController *)editorController
3737
enabled:(BOOL)isEnabled;
@@ -41,7 +41,7 @@ WPEditorViewControllerMode;
4141
* @details The editor fields will be nil before this method is called. This is because editor
4242
* fields are created as part of the process of loading the HTML.
4343
*
44-
* @param editorView The editor view.
44+
* @param editorViewController The editor view controller.
4545
* @param field The new field.
4646
*/
4747
- (void)editorViewController:(WPEditorViewController*)editorViewController
@@ -50,7 +50,7 @@ WPEditorViewControllerMode;
5050
/**
5151
* @brief Received when the user taps on a image in the editor.
5252
*
53-
* @param editorView The editor view.
53+
* @param editorViewController The editor view controller.
5454
* @param imageId The id of image of the image that was tapped.
5555
* @param url The url of the image that was tapped.
5656
*
@@ -62,7 +62,7 @@ WPEditorViewControllerMode;
6262
/**
6363
* @brief Received when the user taps on a image in the editor.
6464
*
65-
* @param editorView The editor view.
65+
* @param editorViewController The editor view controller.
6666
* @param imageId The id of image of the image that was tapped.
6767
* @param url The url of the image that was tapped.
6868
* @param imageMeta The parsed meta data about the image.
@@ -75,7 +75,7 @@ WPEditorViewControllerMode;
7575
/**
7676
* @brief Received when the user taps on a image in the editor.
7777
*
78-
* @param editorView The editor view.
78+
* @param editorViewController The editor view controller.
7979
* @param videoID The id of the video that was tapped.
8080
* @param url The url of the video that was tapped.
8181
*
@@ -87,7 +87,7 @@ WPEditorViewControllerMode;
8787
/**
8888
* @brief Received when the local image url is replace by the final image in the editor.
8989
*
90-
* @param editorView The editor view.
90+
* @param editorViewController The editor view controller.
9191
* @param imageId The id of image of the image that was tapped.
9292
*/
9393
- (void)editorViewController:(WPEditorViewController*)editorViewController
@@ -96,7 +96,7 @@ WPEditorViewControllerMode;
9696
/**
9797
* @brief Received when the local video url is replace by the final video in the editor.
9898
*
99-
* @param editorView The editor view.
99+
* @param editorViewController The editor view controller.
100100
* @param videoID The id of video that was tapped.
101101
*/
102102
- (void)editorViewController:(WPEditorViewController*)editorViewController
@@ -106,7 +106,7 @@ WPEditorViewControllerMode;
106106
* @brief Received when an image is pasted into the editor.
107107
*
108108
* @param editorViewController The editor view controller.
109-
* @param imageId The id of image of the image that was pasted.
109+
* @param image The image that was pasted.
110110
*
111111
*/
112112
- (void)editorViewController:(WPEditorViewController*)editorViewController
@@ -115,7 +115,7 @@ WPEditorViewControllerMode;
115115
/**
116116
* @brief Received when the editor requests information about a videopress video.
117117
*
118-
* @param editorView The editor view.
118+
* @param editorViewController The editor view controller.
119119
* @param videoID The id of video that was tapped.
120120
*/
121121
- (void)editorViewController:(WPEditorViewController *)editorViewController
@@ -124,7 +124,7 @@ WPEditorViewControllerMode;
124124
/**
125125
* @brief Received when the editor removed an uploading media.
126126
*
127-
* @param editorView The editor view.
127+
* @param editorViewController The editor view controller.
128128
* @param mediaID The id of the media that was removed.
129129
*/
130130
- (void)editorViewController:(WPEditorViewController *)editorViewController

Classes/WPEditorViewController.m

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,9 @@ - (void)didTouchMediaOptions
354354
animated:YES
355355
completion:nil];
356356
}
357-
[self.delegate editorTrackStat:WPEditorStatTappedImage];
357+
if ([self.delegate respondsToSelector: @selector(editorTrackStat:)]) {
358+
[self.delegate editorTrackStat:WPEditorStatTappedImage];
359+
}
358360
}
359361

360362
#pragma mark - Editor and Misc Methods
@@ -518,7 +520,9 @@ - (void)showHTMLSource:(UIBarButtonItem *)barButtonItem
518520
setSelected:NO];
519521
}
520522

521-
[self.delegate editorTrackStat:WPEditorStatTappedHTML];
523+
if ([self.delegate respondsToSelector: @selector(editorTrackStat:)]) {
524+
[self.delegate editorTrackStat:WPEditorStatTappedHTML];
525+
}
522526
}
523527

524528
- (void)removeFormat
@@ -550,21 +554,27 @@ - (void)setBold
550554
{
551555
[self.editorView setBold];
552556
[self clearToolbar];
553-
[self.delegate editorTrackStat:WPEditorStatTappedBold];
557+
if ([self.delegate respondsToSelector: @selector(editorTrackStat:)]) {
558+
[self.delegate editorTrackStat:WPEditorStatTappedBold];
559+
}
554560
}
555561

556562
- (void)setBlockQuote
557563
{
558564
[self.editorView setBlockQuote];
559565
[self clearToolbar];
560-
[self.delegate editorTrackStat:WPEditorStatTappedBlockquote];
566+
if ([self.delegate respondsToSelector: @selector(editorTrackStat:)]) {
567+
[self.delegate editorTrackStat:WPEditorStatTappedBlockquote];
568+
}
561569
}
562570

563571
- (void)setItalic
564572
{
565573
[self.editorView setItalic];
566574
[self clearToolbar];
567-
[self.delegate editorTrackStat:WPEditorStatTappedItalic];
575+
if ([self.delegate respondsToSelector: @selector(editorTrackStat:)]) {
576+
[self.delegate editorTrackStat:WPEditorStatTappedItalic];
577+
}
568578
}
569579

570580
- (void)setSubscript
@@ -576,7 +586,9 @@ - (void)setUnderline
576586
{
577587
[self.editorView setUnderline];
578588
[self clearToolbar];
579-
[self.delegate editorTrackStat:WPEditorStatTappedUnderline];
589+
if ([self.delegate respondsToSelector: @selector(editorTrackStat:)]) {
590+
[self.delegate editorTrackStat:WPEditorStatTappedUnderline];
591+
}
580592
}
581593

582594
- (void)setSuperscript
@@ -588,21 +600,27 @@ - (void)setStrikethrough
588600
{
589601
[self.editorView setStrikethrough];
590602
[self clearToolbar];
591-
[self.delegate editorTrackStat:WPEditorStatTappedStrikethrough];
603+
if ([self.delegate respondsToSelector: @selector(editorTrackStat:)]) {
604+
[self.delegate editorTrackStat:WPEditorStatTappedStrikethrough];
605+
}
592606
}
593607

594608
- (void)setUnorderedList
595609
{
596610
[self.editorView setUnorderedList];
597611
[self clearToolbar];
598-
[self.delegate editorTrackStat:WPEditorStatTappedUnorderedList];
612+
if ([self.delegate respondsToSelector: @selector(editorTrackStat:)]) {
613+
[self.delegate editorTrackStat:WPEditorStatTappedUnorderedList];
614+
}
599615
}
600616

601617
- (void)setOrderedList
602618
{
603619
[self.editorView setOrderedList];
604620
[self clearToolbar];
605-
[self.delegate editorTrackStat:WPEditorStatTappedOrderedList];
621+
if ([self.delegate respondsToSelector: @selector(editorTrackStat:)]) {
622+
[self.delegate editorTrackStat:WPEditorStatTappedOrderedList];
623+
}
606624
}
607625

608626
- (void)setHR
@@ -698,7 +716,9 @@ - (void)linkBarButtonTapped
698716
} else {
699717
[self showInsertLinkDialogWithLink:self.editorView.selectedLinkURL
700718
title:[self.editorView selectedText]];
701-
[self.delegate editorTrackStat:WPEditorStatTappedLink];
719+
if ([self.delegate respondsToSelector: @selector(editorTrackStat:)]) {
720+
[self.delegate editorTrackStat:WPEditorStatTappedLink];
721+
}
702722
}
703723
}
704724

@@ -822,7 +842,9 @@ - (void)updateLink:(NSString *)url
822842
- (void)removeLink
823843
{
824844
[self.editorView removeLink];
825-
[self.delegate editorTrackStat:WPEditorStatTappedUnlink];
845+
if ([self.delegate respondsToSelector: @selector(editorTrackStat:)]) {
846+
[self.delegate editorTrackStat:WPEditorStatTappedUnlink];
847+
}
826848
}
827849

828850
- (void)quickLink
@@ -844,8 +866,6 @@ - (void)updateImage:(NSString *)url alt:(NSString *)alt
844866

845867
/**
846868
* @brief Returns an URL from the general pasteboard.
847-
*
848-
* @param The URL or nil if no valid URL is found.
849869
*/
850870
- (NSURL*)urlFromPasteboard
851871
{

0 commit comments

Comments
 (0)