Skip to content

Commit a8077e1

Browse files
authored
Merge pull request wix-incubator#28 from philpettican/bugfix/insert-mention-apostrophe
insert-mention-apostrophe: Escape mention data.
2 parents a222a56 + 66672cc commit a8077e1

File tree

6 files changed

+70
-51
lines changed

6 files changed

+70
-51
lines changed

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ To know when the title or content are in focus, use the following methods.
155155

156156
To start the @mentioning process, use the following method:
157157

158-
- `startMention`
158+
- `startMention()`
159159

160160
To insert an @mention, first either type an @ character to start the @mentioning process or call the startMention method, then use the following method:
161161

@@ -165,6 +165,22 @@ This method registers a function that will get called whenver the cursor positio
165165

166166
- `registerToolbar(listener)`
167167

168+
## Testing changes using the example app
169+
170+
- Install `yalc` globally. See https://www.npmjs.com/package/yalc for more details
171+
- `$ yarn`
172+
- `$ cd ios && pod install && cd ..`
173+
- `$ bash build.sh`
174+
- `$ react-native run-ios`
175+
- or
176+
- `$ react-native run-android`
177+
- In order for the example app to refresh with the latest changes, you need to:
178+
- re-run `$ bash build.sh`
179+
- Stop and restart the metro bundler and then run
180+
- `$ react-native run-ios`
181+
- or
182+
- `$ react-native run-android`
183+
168184
### Example Usage:
169185

170186
```javascript

example/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
cd ..
22
yalc publish
33
cd example/
4-
yalc update react-native-zss-rich-text-editor
4+
yalc add react-native-zss-rich-text-editor

example/package.json

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
{
2-
"name": "example",
3-
"version": "0.0.1",
4-
"private": true,
5-
"scripts": {
6-
"android": "react-native run-android",
7-
"ios": "react-native run-ios",
8-
"start": "react-native start",
9-
"test": "jest",
10-
"lint": "eslint ."
11-
},
12-
"dependencies": {
13-
"react": "16.9.0",
14-
"react-native": "0.61.5",
15-
"react-native-keyboard-spacer": "^0.4.1",
16-
"react-native-webview": "^8.1.2",
17-
"react-native-zss-rich-text-editor": "file:.yalc/react-native-zss-rich-text-editor"
18-
},
19-
"devDependencies": {
20-
"@babel/core": "^7.7.7",
21-
"@babel/runtime": "^7.7.7",
22-
"@react-native-community/eslint-config": "^0.0.5",
23-
"babel-jest": "^24.9.0",
24-
"eslint": "^6.8.0",
25-
"jest": "^24.9.0",
26-
"metro-react-native-babel-preset": "^0.57.0",
27-
"react-test-renderer": "16.9.0"
28-
},
29-
"jest": {
30-
"preset": "react-native"
31-
}
2+
"name": "example",
3+
"version": "0.0.1",
4+
"private": true,
5+
"scripts": {
6+
"android": "react-native run-android",
7+
"ios": "react-native run-ios",
8+
"start": "react-native start",
9+
"test": "jest",
10+
"lint": "eslint ."
11+
},
12+
"dependencies": {
13+
"react": "16.9.0",
14+
"react-native": "0.61.5",
15+
"react-native-keyboard-spacer": "^0.4.1",
16+
"react-native-webview": "^8.1.2",
17+
"react-native-zss-rich-text-editor": "file:../"
18+
},
19+
"devDependencies": {
20+
"@babel/core": "^7.7.7",
21+
"@babel/runtime": "^7.7.7",
22+
"@react-native-community/eslint-config": "^0.0.5",
23+
"babel-jest": "^24.9.0",
24+
"eslint": "^6.8.0",
25+
"jest": "^24.9.0",
26+
"metro-react-native-babel-preset": "^0.57.0",
27+
"react-test-renderer": "16.9.0"
28+
},
29+
"jest": {
30+
"preset": "react-native"
31+
}
3232
}

example/yalc.lock

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/RichTextEditor.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ export default class RichTextEditor extends Component {
115115
const { marginTop = 0, marginBottom = 0 } = this.props.style;
116116
const spacing = marginTop + marginBottom + top + bottom;
117117

118-
const editorAvailableHeight = Dimensions.get('window').height - keyboardHeight * 2 - spacing;
118+
const editorAvailableHeight =
119+
Dimensions.get('window').height - keyboardHeight * 2 - spacing;
119120
this.setEditorHeight(editorAvailableHeight);
120121
}
121122

@@ -803,7 +804,16 @@ export default class RichTextEditor extends Component {
803804
}
804805

805806
insertMention(url, title, className) {
806-
this._sendAction(actions.insertMention, { url, title, className });
807+
const escapedUrl = url ? this.escapeJSONString(url) : url;
808+
const escapedTitle = title ? this.escapeJSONString(title) : title;
809+
const escapedClassName = className
810+
? this.escapeJSONString(className)
811+
: className;
812+
this._sendAction(actions.insertMention, {
813+
url: escapedUrl,
814+
title: escapedTitle,
815+
className: escapedClassName,
816+
});
807817
}
808818

809819
_onMentioning(message) {

src/assets/editor.html

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8705,7 +8705,7 @@
87058705
// Next line is comented to prevent deselecting selection. It looks like work but if there are any issues will appear then uconmment it as well as code above.
87068706
//sel.collapseToStart();
87078707
var range = sel.getRangeAt(0);
8708-
var span = document.createElement('span');// something happening here preventing selection of elements
8708+
var span = document.createElement('span'); // something happening here preventing selection of elements
87098709
if (zss_editor.isUsingiOS) {
87108710
range.collapse(false);
87118711
}
@@ -8973,7 +8973,7 @@
89738973
/* zss_editor.log(`insertExternalCSS: ${uri}`); */
89748974
const link = document.createElement('link');
89758975
link.setAttribute('rel', 'stylesheet');
8976-
link.setAttribute('href', uri);
8976+
link.setAttribute('href', encodeHtmlEntities(uri));
89778977
link.onerror = () => {
89788978
zss_editor.log(`insertExternalCSS: ${uri} link failed`);
89798979
};
@@ -9005,8 +9005,8 @@
90059005

90069006
if (zss_editor.currentEditingLink) {
90079007
var c = zss_editor.currentEditingLink;
9008-
c.attr('href', url);
9009-
c.attr('class', className);
9008+
c.attr('href', encodeHtmlEntities(url));
9009+
c.attr('class', encodeHtmlEntities(className));
90109010
c.text(title);
90119011
}
90129012
zss_editor.enabledEditingItems();
@@ -9017,9 +9017,12 @@
90179017
`insertMention('${url}', '${title}', '${className}')`,
90189018
); */
90199019
var mentionLinkElement = document.createElement('a');
9020-
mentionLinkElement.className = className;
9021-
mentionLinkElement.setAttribute('href', url);
9022-
mentionLinkElement.textContent = title;
9020+
mentionLinkElement.className = encodeHtmlEntities(className);
9021+
mentionLinkElement.setAttribute(
9022+
'href',
9023+
encodeHtmlEntities(url),
9024+
);
9025+
mentionLinkElement.textContent = encodeHtmlEntities(title);
90239026
var space = document.createElement('span');
90249027
space.innerHTML = '\xa0';
90259028
zss_editor.replaceMentionWithElement(mentionLinkElement);

0 commit comments

Comments
 (0)