Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
todomvc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Sven Franck
todomvc
Commits
2af349ab
Commit
2af349ab
authored
Mar 17, 2015
by
Pascal Hartig
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1214 from evverx/escape-user-input
Escape input to prevent funny effects
parents
28b669e4
732a687a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
1 deletion
+23
-1
examples/vanillajs/js/template.js
examples/vanillajs/js/template.js
+23
-1
No files found.
examples/vanillajs/js/template.js
View file @
2af349ab
...
...
@@ -2,6 +2,28 @@
(
function
(
window
)
{
'
use strict
'
;
var
htmlEscapes
=
{
'
&
'
:
'
&
'
,
'
<
'
:
'
<
'
,
'
>
'
:
'
>
'
,
'
"
'
:
'
"
'
,
'
\'
'
:
'
'
'
,
'
`
'
:
'
`
'
};
var
escapeHtmlChar
=
function
(
chr
)
{
return
htmlEscapes
[
chr
];
};
var
reUnescapedHtml
=
/
[
&<>"'`
]
/g
,
reHasUnescapedHtml
=
new
RegExp
(
reUnescapedHtml
.
source
);
var
escape
=
function
(
string
)
{
return
(
string
&&
reHasUnescapedHtml
.
test
(
string
))
?
string
.
replace
(
reUnescapedHtml
,
escapeHtmlChar
)
:
string
;
};
/**
* Sets up defaults for all the Template methods such as a default template
*
...
...
@@ -50,7 +72,7 @@
}
template
=
template
.
replace
(
'
{{id}}
'
,
data
[
i
].
id
);
template
=
template
.
replace
(
'
{{title}}
'
,
data
[
i
].
title
);
template
=
template
.
replace
(
'
{{title}}
'
,
escape
(
data
[
i
].
title
)
);
template
=
template
.
replace
(
'
{{completed}}
'
,
completed
);
template
=
template
.
replace
(
'
{{checked}}
'
,
checked
);
...
...
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