Skip to content

Commit 5171948

Browse files
committed
haha regex bad haha
1 parent 809bcd2 commit 5171948

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

src/lib/hash-parser-hoc.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ const HashParserHOC = function (WrappedComponent) {
3737
window.removeEventListener('hashchange', this.handleHashChange);
3838
}
3939
handleHashChange () {
40-
const hashMatch = window.location.hash.match(/#(.+)/);
41-
const hashProjectId = hashMatch === null ? defaultProjectId : hashMatch[1];
40+
const hashMatch = window.location.hash.slice(1);
41+
const hashProjectId = hashMatch === '' ? defaultProjectId : hashMatch;
4242
this.props.setProjectId(hashProjectId.toString());
4343
}
4444
render () {

src/lib/tw-state-manager-hoc.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ const getLocalStorage = key => {
6666
};
6767

6868
const readHashProjectId = () => {
69-
const match = location.hash.match(/#(.+)/);
70-
return match === null ? null : match[1];
69+
const match = location.hash.slice(1);
70+
return match === '' ? null : match;
7171
};
7272

7373
class Router {

src/playground/embed.jsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ import appTarget from './app-target';
1515
const getProjectId = () => {
1616
// For compatibility reasons, we first look at the hash.
1717
// eg. https://turbowarp.org/embed.html#1
18-
const hashMatch = location.hash.match(/#(.+)/);
19-
console.log(hashMatch);
20-
if (hashMatch !== null) {
21-
return hashMatch[1];
18+
const hashMatch = location.hash.slice(1);
19+
if (hashMatch !== '') {
20+
return hashMatch;
2221
}
2322
// Otherwise, we'll recreate what "wildcard" routing does.
2423
// eg. https://turbowarp.org/1/embed

0 commit comments

Comments
 (0)