mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-12 13:13:45 +01:00
[editor-core] speed up non-bmp detection (#34542)
* [editor-core] avoid duplicate non-bmp check on InsertOp.insertion * [editor-core] remove non-bmp check from StringFileData Existing content may contain non-bmp characters. New edits with non-bmp input are rejected via non-bmp check in InsertOp constructor. GitOrigin-RevId: e9ef3a4a8c4696e8dc751325608a788351791d1c
This commit is contained in:
@@ -9,7 +9,6 @@
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
const containsNonBmpChars = require('../util').containsNonBmpChars
|
||||
const EditOperation = require('./edit_operation')
|
||||
const {
|
||||
RetainOp,
|
||||
@@ -287,13 +286,6 @@ class TextOperation extends EditOperation {
|
||||
apply(file) {
|
||||
const str = file.getContent()
|
||||
const operation = this
|
||||
if (containsNonBmpChars(str)) {
|
||||
throw new TextOperation.ApplyError(
|
||||
'The string contains non BMP characters.',
|
||||
operation,
|
||||
str
|
||||
)
|
||||
}
|
||||
if (str.length !== operation.baseLength) {
|
||||
throw new TextOperation.ApplyError(
|
||||
"The operation's base length must be equal to the string's length.",
|
||||
@@ -317,9 +309,6 @@ class TextOperation extends EditOperation {
|
||||
result += str.slice(inputCursor, inputCursor + op.length)
|
||||
inputCursor += op.length
|
||||
} else if (op instanceof InsertOp) {
|
||||
if (containsNonBmpChars(op.insertion)) {
|
||||
throw new InvalidInsertionError(str, op.toJSON())
|
||||
}
|
||||
file.comments.applyInsert(
|
||||
new Range(result.length, op.insertion.length),
|
||||
{ commentIds: op.commentIds }
|
||||
|
||||
@@ -9,16 +9,6 @@ const StringFileData = require('../../lib/file_data/string_file_data')
|
||||
const TextOperation = ot.TextOperation
|
||||
|
||||
describe('StringFileData', function () {
|
||||
it('throws when it contains non BMP chars', function () {
|
||||
const content = '𝌆𝌆𝌆'
|
||||
const fileData = new StringFileData(content)
|
||||
const operation = new TextOperation()
|
||||
operation.insert('aa')
|
||||
expect(() => {
|
||||
fileData.edit(operation)
|
||||
}).to.throw(TextOperation.ApplyError, /string contains non BMP characters/)
|
||||
})
|
||||
|
||||
it('validates string length when edited', function () {
|
||||
const longString = _.repeat('a', TextOperation.MAX_STRING_LENGTH)
|
||||
const fileData = new StringFileData(longString)
|
||||
|
||||
@@ -193,17 +193,6 @@ describe('TextOperation', function () {
|
||||
)
|
||||
})
|
||||
|
||||
it('throws when base string contains non BMP chars', function () {
|
||||
const operation = new TextOperation()
|
||||
const str = '𝌆\n'
|
||||
expect(() => {
|
||||
operation.apply(new StringFileData(str))
|
||||
}).to.throw(
|
||||
TextOperation.UnprocessableError,
|
||||
/string contains non BMP characters/
|
||||
)
|
||||
})
|
||||
|
||||
it('throws at from JSON when it contains non BMP chars', function () {
|
||||
const operation = ['𝌆\n']
|
||||
expect(() => {
|
||||
|
||||
Reference in New Issue
Block a user