Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-6894

YAML saves insert linefeeds resulting in unlimited YAML file growth

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Minor Minor
    • None
    • None
    • None
    • This server is running CraftBukkit version 3397-Spigot-f4ff00f-f3828bb (MC: 1.18.1) (Implementing API version 1.18.1-R0.1-SNAPSHOT)
    • Yes

      Saving a YAML file that uses the |+ block chomping indicator with text that has a trailing line feed in it causes the file to grow by one line every save.

      Expectation is that saving the file should not insert additional linefeeds. For files that are regularly saved, the file will grow very big over time.

      Example starting YAML:

       

      # YAML load and save bug with keep block chomping indicator
      example:
        description: |+
          These lines have a carrage return after them.
          And the carrage return will be duplicated with each save if the
          block chomping indicator + is used. ("keep": keep the line feed, keep trailing blank lines.)
      
      successfully-loaded: test 

      with this example code that just loads and saves the YAML config file:

       

       

      public class TestPlugin extends JavaPlugin {
          @Override
          public void onEnable() {
              getLogger().info("Test plugin loaded");
              this.saveResource("en-US.yml", false);
              File targetFile = new File(this.getDataFolder(), "en-US.yml");
              // Repeatedly load and save every second just to demonstrate issue
              Bukkit.getScheduler().runTaskTimer(this, () -> {
                  YamlConfiguration fileLocale = new YamlConfiguration();
                  try {
                      // Load it
                      fileLocale.load(targetFile);
                      // Save it
                      fileLocale.save(targetFile);
                      getLogger().info("Saved");
                  } catch (IOException | InvalidConfigurationException e) {
                      e.printStackTrace();
                  }
              }, 20, 20);
          }
      }

      After a few seconds, the YAML file will look like this (and the gap will keep growing):

       

       

      example:
        description: |+
          These lines have a carrage return after them.
          And the carrage return will be duplicated with each save if the
          block chomping indicator + is used. ("keep": keep the line feed, keep trailing blank lines.)
      
      
      
      
      
      
      
      
      
      successfully-loaded: test
       

      The only workaround is to avoid using the |+ block chomping symbol in the YAML. For example if just | is used, or |- then it won't occur, but also technically this means that the block text cannot have a trailing free line after it.

       

            Unassigned Unassigned
            tastybento tastybento
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: