Skip to content

Commit

Permalink
Merge pull request #1822 from filipedeschamps/perf/content-cleaning
Browse files Browse the repository at this point in the history
Melhora o desempenho da RegEx que evita a criação de conteúdos invisíveis
  • Loading branch information
aprendendofelipe authored Nov 29, 2024
2 parents c747083 + a64c4b6 commit 4d422bb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion models/remove-markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default function removeMarkdown(md, options = {}) {

if (options.trim) {
output = output.replace(
/^(\s|\p{C}|\u2800|\u034f|\u115f|\u1160|\u17b4|\u17b5|\u3164|\uffa0)+|(\s|\p{C}|\u2800|\u034f|\u115f|\u1160|\u17b4|\u17b5|\u3164|\uffa0)+$|\u0000/gsu,
/^[\s\p{C}\u034f\u17b4\u17b5\u2800\u115f\u1160\u3164\uffa0]+|[\s\p{C}\u034f\u17b4\u17b5\u2800\u115f\u1160\u3164\uffa0]+$|\u0000/gsu,
'',
);
}
Expand Down
8 changes: 4 additions & 4 deletions models/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ const schemas = {
description: function () {
return Joi.object({
description: Joi.string()
.replace(/(\s|\p{C}|\u2800|\u034f|\u115f|\u1160|\u17b4|\u17b5|\u3164|\uffa0)+$|\u0000/gsu, '')
.replace(/[\s\p{C}\u034f\u17b4\u17b5\u2800\u115f\u1160\u3164\uffa0]+$|\u0000/gsu, '')
.max(5000)
.allow('')
.when('$required.description', { is: 'required', then: Joi.required(), otherwise: Joi.optional() }),
Expand Down Expand Up @@ -231,7 +231,7 @@ const schemas = {
return Joi.object({
title: Joi.string()
.replace(
/^(\s|\p{C}|\u2800|\u034f|\u115f|\u1160|\u17b4|\u17b5|\u3164|\uffa0)+|(\s|\p{C}|\u2800|\u034f|\u115f|\u1160|\u17b4|\u17b5|\u3164|\uffa0)+$|\u0000/gu,
/^[\s\p{C}\u034f\u17b4\u17b5\u2800\u115f\u1160\u3164\uffa0]+|[\s\p{C}\u034f\u17b4\u17b5\u2800\u115f\u1160\u3164\uffa0]+$|\u0000/gu,
'',
)
.min(1)
Expand All @@ -243,8 +243,8 @@ const schemas = {
body: function () {
return Joi.object({
body: Joi.string()
.pattern(/^(\s|\p{C}|\u2800|\u034f|\u115f|\u1160|\u17b4|\u17b5|\u3164|\uffa0).*$/su, { invert: true })
.replace(/(\s|\p{C}|\u2800|\u034f|\u115f|\u1160|\u17b4|\u17b5|\u3164|\uffa0)+$|\u0000/gsu, '')
.pattern(/^[\s\p{C}\u034f\u17b4\u17b5\u2800\u115f\u1160\u3164\uffa0].*$/su, { invert: true })
.replace(/[\s\p{C}\u034f\u17b4\u17b5\u2800\u115f\u1160\u3164\uffa0]+$|\u0000/gsu, '')
.min(1)
.max(20000)
.custom(withoutMarkdown, 'check if is empty without markdown')
Expand Down

0 comments on commit 4d422bb

Please sign in to comment.