0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-09 09:22:38 +00:00

Merge pull request #4311 from dbolack-ab/md5Fix

Normalize strings before running MD5s
This commit is contained in:
Trevor Buckner
2025-07-09 22:40:15 -04:00
committed by GitHub
3 changed files with 11 additions and 8 deletions

View File

@@ -259,12 +259,14 @@ const EditPage = createClass({
const preSaveSnapshot = { ...this.state.brew }; const preSaveSnapshot = { ...this.state.brew };
//Prepare content to send to server //Prepare content to send to server
const brew = { ...this.state.brew }; const brew = { ...this.state.brew };
brew.pageCount = ((brew.renderer=='legacy' ? brew.text.match(/\\page/g) : brew.text.match(/^\\page$/gm)) || []).length + 1; brew.text = brew.text.normalize();
brew.patches = stringifyPatches(makePatches(this.savedBrew.text, brew.text)); this.savedBrew.text = this.savedBrew.text.normalize();
brew.hash = await md5(this.savedBrew.text); brew.pageCount = ((brew.renderer=='legacy' ? brew.text.match(/\\page/g) : brew.text.match(/^\\page$/gm)) || []).length + 1;
brew.text = undefined; brew.patches = stringifyPatches(makePatches(this.savedBrew.text, brew.text));
brew.textBin = undefined; brew.hash = await md5(this.savedBrew.text);
brew.text = undefined;
brew.textBin = undefined;
const transfer = this.state.saveGoogle == _.isNil(this.state.brew.googleId); const transfer = this.state.saveGoogle == _.isNil(this.state.brew.googleId);
const params = `${transfer ? `?${this.state.saveGoogle ? 'saveToGoogle' : 'removeFromGoogle'}=true` : ''}`; const params = `${transfer ? `?${this.state.saveGoogle ? 'saveToGoogle' : 'removeFromGoogle'}=true` : ''}`;

View File

@@ -72,7 +72,7 @@
"lines": 50 "lines": 50
}, },
"server/homebrew.api.js": { "server/homebrew.api.js": {
"statements": 70, "statements": 69,
"branches": 50, "branches": 50,
"functions": 65, "functions": 65,
"lines": 70 "lines": 70

View File

@@ -340,7 +340,8 @@ const api = {
const brewFromClient = api.excludePropsFromUpdate(req.body); const brewFromClient = api.excludePropsFromUpdate(req.body);
const brewFromServer = req.brew; const brewFromServer = req.brew;
splitTextStyleAndMetadata(brewFromServer); splitTextStyleAndMetadata(brewFromServer);
brewFromServer.text = brewFromServer.text.normalize();
brewFromServer.hash = await md5(brewFromServer.text); brewFromServer.hash = await md5(brewFromServer.text);
if((brewFromServer?.version !== brewFromClient?.version) || (brewFromServer?.hash !== brewFromClient?.hash)) { if((brewFromServer?.version !== brewFromClient?.version) || (brewFromServer?.hash !== brewFromClient?.hash)) {