Skip to content

Commit 99d23f6

Browse files
committed
fix: don't escape HTML in templates
When using `<%= code %>` in `ejs`, it escapes characters by default. This is useful when writing HTML, but in our case, it may sometimes lead to undesirable behavior. For example, if you generate a project with the description "Satya's cool library", it would escape `'` and output: "Satya&#39 cool library". This commit swaps the templates to use `<%- code %>` so that nothing is escaped.
1 parent fc0b524 commit 99d23f6

File tree

63 files changed

+245
-245
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+245
-245
lines changed

templates/common/$package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"name": "<%= project.slug %>",
2+
"name": "<%- project.slug %>",
33
"version": "0.1.0",
4-
"description": "<%= project.description %>",
4+
"description": "<%- project.description %>",
55
"main": "lib/commonjs/index",
66
"module": "lib/module/index",
77
"types": "lib/typescript/src/index.d.ts",
@@ -13,7 +13,7 @@
1313
"android",
1414
"ios",
1515
"cpp",
16-
"<%= project.podspec %>.podspec",
16+
"<%- project.podspec %>.podspec",
1717
"!lib/typescript/example",
1818
"!android/build",
1919
"!ios/build",
@@ -36,19 +36,19 @@
3636
"ios",
3737
"android"
3838
],
39-
"repository": "<%= repo %>",
40-
"author": "<%= author.name %> <<%= author.email %>> (<%= author.url %>)",
39+
"repository": "<%- repo %>",
40+
"author": "<%- author.name %> <<%- author.email %>> (<%- author.url %>)",
4141
"license": "MIT",
4242
"bugs": {
43-
"url": "<%= repo %>/issues"
43+
"url": "<%- repo %>/issues"
4444
},
45-
"homepage": "<%= repo %>#readme",
45+
"homepage": "<%- repo %>#readme",
4646
"publishConfig": {
4747
"registry": "https://registry.npmjs.org/"
4848
},
4949
"devDependencies": {
5050
"@commitlint/config-conventional": "^8.3.4",
51-
"@react-native-community/bob": "^<%= bob.version %>",
51+
"@react-native-community/bob": "^<%- bob.version %>",
5252
"@react-native-community/eslint-config": "^2.0.0",
5353
"@release-it/conventional-changelog": "^1.1.4",
5454
"@types/jest": "^26.0.0",

templates/common/CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ Remember to add tests for your change if possible. Run the unit tests by:
5555
yarn test
5656
```
5757
<% if (project.native) { %>
58-
To edit the Objective-C files, open `example/ios/<%= project.name %>Example.xcworkspace` in XCode and find the source files at `Pods > Development Pods > <%= project.slug %>`.
58+
To edit the Objective-C files, open `example/ios/<%- project.name %>Example.xcworkspace` in XCode and find the source files at `Pods > Development Pods > <%- project.slug %>`.
5959

60-
To edit the Kotlin files, open `example/android` in Android studio and find the source files at `<%= project.package %>` under `Android`.
60+
To edit the Kotlin files, open `example/android` in Android studio and find the source files at `<%- project.package %>` under `Android`.
6161
<% } %>
6262
### Commit message convention
6363

templates/common/LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2020 <%= author.name %>
3+
Copyright (c) 2020 <%- author.name %>
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

templates/common/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
# <%= project.slug %>
1+
# <%- project.slug %>
22

3-
<%= project.description %>
3+
<%- project.description %>
44

55
## Installation
66

77
```sh
8-
npm install <%= project.slug %>
8+
npm install <%- project.slug %>
99
```
1010

1111
## Usage
1212

1313
```js
14-
import <%= project.name %> from "<%= project.slug %>";
14+
import <%- project.name %> from "<%- project.slug %>";
1515

1616
// ...
1717

18-
const result = await <%= project.name %>.multiply(3, 7);
18+
const result = await <%- project.name %>.multiply(3, 7);
1919
```
2020

2121
## Contributing

templates/common/example/src/App.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import * as React from 'react';
22
<% if (project.moduleType === "view") { %>
33
import { StyleSheet, View } from 'react-native';
4-
import <%= project.name %>ViewManager from '<%= project.slug %>';
4+
import <%- project.name %>ViewManager from '<%- project.slug %>';
55
<% } else {%>
66
import { StyleSheet, View, Text } from 'react-native';
7-
import <%= project.name %> from '<%= project.slug %>';
7+
import <%- project.name %> from '<%- project.slug %>';
88
<% }%>
99

1010
<% if (project.moduleType === "view") { %>
1111
export default function App() {
1212
return (
1313
<View style={styles.container}>
14-
<<%= project.name %>ViewManager color="#32a852" style={styles.box} />
14+
<<%- project.name %>ViewManager color="#32a852" style={styles.box} />
1515
</View>
1616
);
1717
}
@@ -20,15 +20,15 @@ export default function App() {
2020
const [result, setResult] = React.useState<number | undefined>();
2121

2222
React.useEffect(() => {
23-
<%= project.name %>.multiply(3, 7).then(setResult);
23+
<%- project.name %>.multiply(3, 7).then(setResult);
2424
}, []);
2525

2626
return (
2727
<View style={styles.container}>
2828
<Text>Result: {result}</Text>
2929
</View>
3030
);
31-
}
31+
}
3232
<% }%>
3333

3434
const styles = StyleSheet.create({
@@ -42,4 +42,4 @@ const styles = StyleSheet.create({
4242
height: 60,
4343
marginVertical: 20,
4444
},
45-
});
45+
});

templates/common/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"compilerOptions": {
33
"baseUrl": ".",
44
"paths": {
5-
"<%= project.slug %>": ["./src/index"]
5+
"<%- project.slug %>": ["./src/index"]
66
},
77
"allowUnreachableCode": false,
88
"allowUnusedLabels": false,

templates/cpp-library/android/cpp-adapter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33

44
extern "C"
55
JNIEXPORT jint JNICALL
6-
Java_com_<%= project.package %>_<%= project.name %>Module_nativeMultiply(JNIEnv *env, jclass type, jint a, jint b) {
6+
Java_com_<%- project.package %>_<%- project.name %>Module_nativeMultiply(JNIEnv *env, jclass type, jint a, jint b) {
77
return example::multiply(a, b);
88
}

templates/cpp-library/ios/{%= project.name %}.h renamed to templates/cpp-library/ios/{%- project.name %}.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66

77
#endif
88

9-
@interface <%= project.name %> : NSObject <RCTBridgeModule>
9+
@interface <%- project.name %> : NSObject <RCTBridgeModule>
1010

1111
@end

templates/cpp-library/ios/{%= project.name %}.mm renamed to templates/cpp-library/ios/{%- project.name %}.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#import "<%= project.name %>.h"
1+
#import "<%- project.name %>.h"
22

3-
@implementation <%= project.name %>
3+
@implementation <%- project.name %>
44

55
RCT_EXPORT_MODULE()
66

templates/example/example/$package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "<%= project.slug %>-example",
3-
"description": "Example app for <%= project.slug %>",
2+
"name": "<%- project.slug %>-example",
3+
"description": "Example app for <%- project.slug %>",
44
"version": "0.0.1",
55
"private": true,
66
"scripts": {

0 commit comments

Comments
 (0)