Skip to content

Patch method breaks the array of strings #10

Description

@antoniofarina

Hi,
consider the code below.
As you can see, altering the disableLanguages array (removing an item) the patch method breaks the disableLanguages array

NOTE

the input is a part of a longer config file but, consider that I have checked the issue on the whole file. I also tried to change the spacing between elements in the disableLanguages array (["he", "hu", "zh", "nb", "da", "ro", "fi"], ['he', 'hu', 'zh', 'nb', 'da', 'ro', 'fi'], ["he","hu","zh","nb","da","ro","fi"], ['he','hu','zh','nb','da','ro','fi'], ... and so on ) with the same result

let tomlFileContent= 'baseUrl = "https://example.com/"
languageCode = "en-us"
languageLang = "en"
title = "this is the title"
DefaultContentLanguage = "en"
disableLanguages = ["he", "hu", "zh", "nb", "da", "ro", "fi"]'

value= parse(tomlFileContent)

console.log (value.disableLanguages)
## output  [ "he", "hu", "zh", "nb", "da", "ro", "fi" ]
for (var i = 0; i < value.disableLanguages.length; i++) {
        if (value.disableLanguages[i] === 'he') {
            value.disableLanguages.splice(i, 1);
            i--;
        }
    }
console.log (value.disableLanguages)
## output  ["hu", "zh", "nb", "da", "ro", "fi"]

console.log (patch(tomlFileContent, value))
### output 
baseUrl = "https://example.com/"
languageCode = "en-us"
languageLang = "en"
title = "this is the title"
DefaultContentLanguage = "en"
disableLanguages = ["he", "hu", "zh", "nb", "da", "ro", "fi"    <---- BROKEN !!!!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions