Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Luc Bourdot
codimd
Commits
d9e19b60
Commit
d9e19b60
authored
Jan 02, 2017
by
Wu Cheng-Han
Browse files
Update to remove null byte before saving to DB and remove null byte on changes
parent
c3a96ff1
Changes
4
Hide whitespace changes
Inline
Side-by-side
lib/models/index.js
View file @
d9e19b60
...
...
@@ -20,6 +20,13 @@ if (config.dburl)
else
sequelize
=
new
Sequelize
(
dbconfig
.
database
,
dbconfig
.
username
,
dbconfig
.
password
,
dbconfig
);
// [Postgres] Handling NULL bytes
// https://github.com/sequelize/sequelize/issues/6485
function
stripNullByte
(
value
)
{
return
value
?
value
.
replace
(
/
\u
0000/g
,
""
)
:
value
;
}
sequelize
.
stripNullByte
=
stripNullByte
;
var
db
=
{};
fs
...
...
lib/models/note.js
View file @
d9e19b60
...
...
@@ -52,13 +52,22 @@ module.exports = function (sequelize, DataTypes) {
defaultValue
:
0
},
title
:
{
type
:
DataTypes
.
TEXT
type
:
DataTypes
.
TEXT
,
set
:
function
(
value
)
{
this
.
setDataValue
(
'
title
'
,
sequelize
.
stripNullByte
(
value
));
}
},
content
:
{
type
:
DataTypes
.
TEXT
type
:
DataTypes
.
TEXT
,
set
:
function
(
value
)
{
this
.
setDataValue
(
'
content
'
,
sequelize
.
stripNullByte
(
value
));
}
},
authorship
:
{
type
:
DataTypes
.
TEXT
type
:
DataTypes
.
TEXT
,
set
:
function
(
value
)
{
this
.
setDataValue
(
'
authorship
'
,
JSON
.
stringify
(
value
));
}
},
lastchangeAt
:
{
type
:
DataTypes
.
DATE
...
...
lib/models/revision.js
View file @
d9e19b60
...
...
@@ -59,19 +59,31 @@ module.exports = function (sequelize, DataTypes) {
defaultValue
:
Sequelize
.
UUIDV4
},
patch
:
{
type
:
DataTypes
.
TEXT
type
:
DataTypes
.
TEXT
,
set
:
function
(
value
)
{
this
.
setDataValue
(
'
patch
'
,
sequelize
.
stripNullByte
(
value
));
}
},
lastContent
:
{
type
:
DataTypes
.
TEXT
type
:
DataTypes
.
TEXT
,
set
:
function
(
value
)
{
this
.
setDataValue
(
'
lastContent
'
,
sequelize
.
stripNullByte
(
value
));
}
},
content
:
{
type
:
DataTypes
.
TEXT
type
:
DataTypes
.
TEXT
,
set
:
function
(
value
)
{
this
.
setDataValue
(
'
content
'
,
sequelize
.
stripNullByte
(
value
));
}
},
length
:
{
type
:
DataTypes
.
INTEGER
},
authorship
:
{
type
:
DataTypes
.
TEXT
type
:
DataTypes
.
TEXT
,
set
:
function
(
value
)
{
this
.
setDataValue
(
'
authorship
'
,
value
?
JSON
.
stringify
(
value
)
:
value
);
}
}
},
{
classMethods
:
{
...
...
public/js/index.js
View file @
d9e19b60
...
...
@@ -3207,6 +3207,12 @@ function buildCursor(user) {
}
//editor actions
function
removeNullByte
(
cm
,
change
)
{
var
str
=
change
.
text
.
join
(
"
\n
"
);
if
(
/
\u
0000/g
.
test
(
str
)
&&
change
.
update
)
{
change
.
update
(
change
.
from
,
change
.
to
,
str
.
replace
(
/
\u
0000/g
,
""
).
split
(
"
\n
"
));
}
}
function
enforceMaxLength
(
cm
,
change
)
{
var
maxLength
=
cm
.
getOption
(
"
maxLength
"
);
if
(
maxLength
&&
change
.
update
)
{
...
...
@@ -3228,6 +3234,7 @@ var ignoreEmitEvents = ['setValue', 'ignoreHistory'];
editor
.
on
(
'
beforeChange
'
,
function
(
cm
,
change
)
{
if
(
debug
)
console
.
debug
(
change
);
removeNullByte
(
cm
,
change
);
if
(
enforceMaxLength
(
cm
,
change
))
{
$
(
'
.limit-modal
'
).
modal
(
'
show
'
);
}
...
...
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