Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
65cc19c1
Unverified
Commit
65cc19c1
authored
Dec 23, 2022
by
boojack
Committed by
GitHub
Dec 23, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: add escape to prevent XSS (#833)
parent
c07b4a57
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
11 additions
and
10 deletions
+11
-10
SearchBar.tsx
web/src/components/SearchBar.tsx
+1
-1
index.ts
web/src/labs/highlighter/index.ts
+3
-5
Bold.ts
web/src/labs/marked/parser/Bold.ts
+2
-1
BoldEmphasis.ts
web/src/labs/marked/parser/BoldEmphasis.ts
+2
-1
Emphasis.ts
web/src/labs/marked/parser/Emphasis.ts
+2
-1
Link.ts
web/src/labs/marked/parser/Link.ts
+1
-1
No files found.
web/src/components/SearchBar.tsx
View file @
65cc19c1
...
@@ -38,7 +38,7 @@ const SearchBar = () => {
...
@@ -38,7 +38,7 @@ const SearchBar = () => {
useEffect
(()
=>
{
useEffect
(()
=>
{
const
text
=
locationStore
.
getState
().
query
.
text
;
const
text
=
locationStore
.
getState
().
query
.
text
;
setQueryText
(
text
===
undefined
?
""
:
text
);
setQueryText
(
text
===
undefined
?
""
:
text
);
},
[
locationStore
.
getState
()
.
query
.
text
]);
},
[
locationStore
.
state
.
query
.
text
]);
const
handleMemoTypeItemClick
=
(
type
:
MemoSpecType
|
undefined
)
=>
{
const
handleMemoTypeItemClick
=
(
type
:
MemoSpecType
|
undefined
)
=>
{
const
{
type
:
prevType
}
=
locationStore
.
getState
().
query
??
{};
const
{
type
:
prevType
}
=
locationStore
.
getState
().
query
??
{};
...
...
web/src/labs/highlighter/index.ts
View file @
65cc19c1
const
escapeRegExp
=
(
str
:
string
):
string
=>
{
import
{
escape
}
from
"lodash"
;
return
str
.
replace
(
/
[
.*+?^${}()|[
\]\\]
/g
,
"
\\
$&"
);
};
const
walkthroughNodeWithKeyword
=
(
node
:
HTMLElement
,
keyword
:
string
)
=>
{
const
walkthroughNodeWithKeyword
=
(
node
:
HTMLElement
,
keyword
:
string
)
=>
{
if
(
node
.
nodeType
===
3
)
{
if
(
node
.
nodeType
===
3
)
{
...
@@ -19,8 +17,8 @@ export const highlightWithWord = (html: string, keyword?: string): string => {
...
@@ -19,8 +17,8 @@ export const highlightWithWord = (html: string, keyword?: string): string => {
if
(
!
keyword
)
{
if
(
!
keyword
)
{
return
html
;
return
html
;
}
}
keyword
=
escape
RegExp
(
keyword
);
keyword
=
escape
(
keyword
);
const
wrap
=
document
.
createElement
(
"div"
);
const
wrap
=
document
.
createElement
(
"div"
);
wrap
.
innerHTML
=
html
;
wrap
.
innerHTML
=
escape
(
html
)
;
return
walkthroughNodeWithKeyword
(
wrap
,
keyword
);
return
walkthroughNodeWithKeyword
(
wrap
,
keyword
);
};
};
web/src/labs/marked/parser/Bold.ts
View file @
65cc19c1
import
{
escape
}
from
"lodash"
;
import
{
marked
}
from
".."
;
import
{
marked
}
from
".."
;
import
Link
from
"./Link"
;
import
Link
from
"./Link"
;
...
@@ -14,7 +15,7 @@ const renderer = (rawStr: string): string => {
...
@@ -14,7 +15,7 @@ const renderer = (rawStr: string): string => {
return
rawStr
;
return
rawStr
;
}
}
const
parsedContent
=
marked
(
matchResult
[
1
]
,
[],
[
Link
]);
const
parsedContent
=
marked
(
escape
(
matchResult
[
1
])
,
[],
[
Link
]);
return
`<strong>
${
parsedContent
}
</strong>`
;
return
`<strong>
${
parsedContent
}
</strong>`
;
};
};
...
...
web/src/labs/marked/parser/BoldEmphasis.ts
View file @
65cc19c1
import
{
escape
}
from
"lodash"
;
import
{
marked
}
from
".."
;
import
{
marked
}
from
".."
;
import
Link
from
"./Link"
;
import
Link
from
"./Link"
;
...
@@ -14,7 +15,7 @@ const renderer = (rawStr: string): string => {
...
@@ -14,7 +15,7 @@ const renderer = (rawStr: string): string => {
return
rawStr
;
return
rawStr
;
}
}
const
parsedContent
=
marked
(
matchResult
[
1
]
,
[],
[
Link
]);
const
parsedContent
=
marked
(
escape
(
matchResult
[
1
])
,
[],
[
Link
]);
return
`<strong><em>
${
parsedContent
}
</em></strong>`
;
return
`<strong><em>
${
parsedContent
}
</em></strong>`
;
};
};
...
...
web/src/labs/marked/parser/Emphasis.ts
View file @
65cc19c1
import
{
escape
}
from
"lodash"
;
import
{
marked
}
from
".."
;
import
{
marked
}
from
".."
;
import
Link
from
"./Link"
;
import
Link
from
"./Link"
;
...
@@ -14,7 +15,7 @@ const renderer = (rawStr: string): string => {
...
@@ -14,7 +15,7 @@ const renderer = (rawStr: string): string => {
return
rawStr
;
return
rawStr
;
}
}
const
parsedContent
=
marked
(
matchResult
[
1
]
,
[],
[
Link
]);
const
parsedContent
=
marked
(
escape
(
matchResult
[
1
])
,
[],
[
Link
]);
return
`<em>
${
parsedContent
}
</em>`
;
return
`<em>
${
parsedContent
}
</em>`
;
};
};
...
...
web/src/labs/marked/parser/Link.ts
View file @
65cc19c1
...
@@ -17,7 +17,7 @@ const renderer = (rawStr: string): string => {
...
@@ -17,7 +17,7 @@ const renderer = (rawStr: string): string => {
if
(
!
matchResult
)
{
if
(
!
matchResult
)
{
return
rawStr
;
return
rawStr
;
}
}
const
parsedContent
=
marked
(
matchResult
[
1
]
,
[],
[
InlineCode
,
BoldEmphasis
,
Emphasis
,
Bold
]);
const
parsedContent
=
marked
(
escape
(
matchResult
[
1
])
,
[],
[
InlineCode
,
BoldEmphasis
,
Emphasis
,
Bold
]);
return
`<a class='link' target='_blank' rel='noreferrer' href='
${
escape
(
matchResult
[
2
])}
'>
${
parsedContent
}
</a>`
;
return
`<a class='link' target='_blank' rel='noreferrer' href='
${
escape
(
matchResult
[
2
])}
'>
${
parsedContent
}
</a>`
;
};
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment