Skip to content

Commit

Permalink
Make sure all original lines exist in sequence within the file before…
Browse files Browse the repository at this point in the history
… replacing them
  • Loading branch information
BenSurgisonGDS committed Mar 29, 2023
1 parent 3843648 commit 4800248
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions migrator/migration-steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,17 @@ window.console.info('GOV.UK Prototype Kit - do not use for production')
while (lastPos < startPos) {
newContentLines.push(fileLines[lastPos++])
}

if (replacementText) {
const replacementLines = replacementText.split('\n')
for (let i = 0; i < replacementLines.length; i++) {
newContentLines.push(replacementLines[i])
// Make sure all original lines exist in sequence within the file before replacing them
const canReplace = originalLines.every((originalLine, index) => {
return originalLine.trim() === fileLines[startPos + index].trim()
})
if (canReplace) {
const replacementLines = replacementText.split('\n')
for (let i = 0; i < replacementLines.length; i++) {
newContentLines.push(replacementLines[i])
}
}
}
})
Expand Down

0 comments on commit 4800248

Please sign in to comment.