Skip to content

Commit 2743c54

Browse files
committed
fix: encoding of urls
1 parent d06721a commit 2743c54

File tree

7 files changed

+63
-36
lines changed

7 files changed

+63
-36
lines changed

components/Check.vue

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,23 @@
5656
const API = ""; //"https://wm.rem.now.sh/api"; //process.env.API;
5757
export default {
5858
props: {
59-
url: String,
59+
query: String
60+
},
61+
data: function () {
62+
return {
63+
url: this.query,
64+
loading: false,
65+
mentions: [],
66+
sent: false,
67+
hasResult: false,
68+
error: null
69+
};
6070
},
61-
data: () => ({
62-
// url: "",
63-
loading: false,
64-
mentions: [],
65-
sent: false,
66-
hasResult: false,
67-
error: null
68-
}),
6971
methods: {
7072
async sendMentions(event) {
7173
event.preventDefault();
7274
this.loading = true;
73-
const res = await fetch(`${API}/check/?url=${escape(this.url)}`, {
75+
const res = await fetch(`${API}/check/?url=${encodeURIComponent(this.url)}`, {
7476
method: "post"
7577
});
7678
this.loading = false;
@@ -91,7 +93,7 @@ export default {
9193
this.hasResult = false;
9294
this.error = null;
9395
this.mentions = [];
94-
const res = await fetch(`${API}/check/?url=${escape(this.url)}`);
96+
const res = await fetch(`${API}/check/?url=${encodeURIComponent(this.url)}`);
9597
9698
if (res.status === 200) {
9799
const json = await res.json();
@@ -110,7 +112,9 @@ export default {
110112
} catch (e) {
111113
console.log(e);
112114
113-
this.error = 'Something went wrong trying to capture the contents of the check request. Please try again or please report this error with the URL you are testing - thank you\n\n' + e;
115+
this.error =
116+
"Something went wrong trying to capture the contents of the check request: " +
117+
e;
114118
}
115119
}
116120
}

lib/query-string.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
const url = require('url');
22
const qsParser = require('querystring').parse;
3+
const decodeUriComponent = require('decodeuricomponent');
34

4-
module.exports = req => qsParser(url.parse(req.url).query);
5+
module.exports = req =>
6+
qsParser(url.parse(req.url).query, null, null, {
7+
decodeURIComponent: decodeUriComponent,
8+
});

package-lock.json

Lines changed: 30 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"cheerio": "0.22.0",
3636
"clui": "^0.3.6",
3737
"cookie-universal-nuxt": "^2.0.14",
38+
"decodeuricomponent": "^0.3.1",
3839
"follow-redirects": "^1.7.0",
3940
"googleapis": "^40.0.0",
4041
"li": "^1.3.0",

pages/docs/todo.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<template lang="md">
22
# TODO
33

4-
- [ ] Support proper host encoding, so https://i❤️.ws works
54
- [ ] Allow self mentions & pings
65
- [ ] Provide `require('@remy/webmention')` support
76
- [ ] Support JSON feed (if there's requests for it)
87
- [ ] Support other sign in methods, such as indieauth
98

109
## As of v1.3.1 / 2019-06-13
1110

11+
- [x] Support proper host encoding, so https://i❤️.ws works
1212
- [x] If both pingback & webmention found, prioritise webmention
1313
- [x] Support nested `h-entry` (such as nested in `h-feed`s)
1414

pages/test.vue

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,20 @@
22
<div>
33
<h1>Test and send webmentions</h1>
44
<p>Keep in mind that this test page only scans the 10 most recent <code>h-entry</code> elements on the target.</p>
5-
<Check :url="url"/>
5+
<Check v-bind:query="url"/>
66
</div>
77
</template>
88

99
<script>
1010
import Check from "../components/Check";
1111
export default {
1212
data() {
13-
return {
14-
url: ''
15-
}
13+
return { url: '' }
1614
},
17-
components: { Check },
18-
mounted() {
19-
if (window.location.search) {
20-
try {
21-
const q = new URLSearchParams(window.location.search);
22-
this.url = q.get("url") || ""
23-
} catch (e) {}
24-
}
25-
}
15+
asyncData ({ query } = {}) {
16+
return query;
17+
},
18+
components: { Check }
2619
};
2720
</script>
2821

routes/check.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const Webmention = require('../lib/webmention');
33
const sendMention = require('../lib/send');
44
const db = require('../lib/db');
55
const ms = require('ms');
6+
const parse = require('url').parse;
67

78
const rateWindow = 1000 * 60; // * 60 * 4; // 4 hours
89

@@ -32,6 +33,9 @@ module.exports = async (req, res) => {
3233
url = `http://${url}`;
3334
}
3435

36+
// ensure the url is properly encoded
37+
url = parse(url).href;
38+
3539
const { origin = '', referer = '' } = req.headers;
3640

3741
if (

0 commit comments

Comments
 (0)