leader-set doesn't preserve newlines

Bug #1527595 reported by Robert Ayres
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Canonical Juju
Won't Fix
Medium
Unassigned
juju-core
Won't Fix
Medium
Unassigned

Bug Description

leader-set, called from within a charm, doesn't preserve newlines (and probably other whitespace) at the end of a value.

For example:

# using bash with debug-hooks

$ leader-set mystring=mystring$'\n\n\n'

$ leader-get mystring
mystring
$

Newlines are preserved in config.yaml values however:

$ juju set <charm> mystring=mystring$'\n\n\n'

# within charm
$ config-get mystring
mystring
<3 more line breaks>
$

I think it could lead to problems if the command is silently altering input. Especially if the charm needs to use multiline strings.

Juju version: 1.25.0-trusty-amd64

description: updated
Changed in juju-core:
status: New → Triaged
importance: Undecided → Medium
Changed in juju-core:
status: Triaged → Won't Fix
Revision history for this message
Robert Ayres (robert-ayres) wrote :

Has this actually been fixed in Juju 2.0?

Just closing for the sake of lowering the bug count won't make bugs go away.

Revision history for this message
Anastasia (anastasia-macmood) wrote :

@Robert
The bug is closed because "juju-core" project tracks bugs for Juju 1. This project only accepts Critical bugs. Consequently, this bug will not be fixed for Juju 1, current series 1.25.

The project that tracks Juju 2 bugs is "juju". We have moved all the bugs that have been explicitly opened against Juju 2. As Juju 2 is very different to Juju 1, majority of bugs against Juju 1 are not applicable.

This one, as you rightly pointed out, needs to be addressed. I'll re-target it to "juju".

We have sent an email out to juju-dev 2 months ago advertising our move. We have also waited for 2 months to make sure that no bugs have been forgotten or left behind before we closed "juju-core". Apologies if decisive closure of this bug took you by surprise :D Thank you for reaching out!

Changed in juju:
status: New → Triaged
importance: Undecided → Medium
milestone: none → 2.0.1
Curtis Hovey (sinzui)
Changed in juju:
milestone: 2.0.1 → none
Revision history for this message
John A Meinel (jameinel) wrote :

Just to mention, this is an explicit trimming of whitespace:
func (c *leaderSetCommand) Init(args []string) (err error) {
 c.settings, err = keyvalues.Parse(args, true)
 return
}
...
func Parse(src []string, allowEmptyValues bool) (map[string]string, error) {
...
  key, value := strings.TrimSpace(parts[0]), strings.TrimSpace(parts[1])

Note, though, that 'relation-set' follows the same code, and I would expect them to behave the same:
func (c *RelationSetCommand) Init(args []string) error {
 if c.RelationId == -1 {
  return errors.Errorf("no relation id specified")
 }

 // The overrides will be applied during Run when c.settingsFile is handled.
 overrides, err := keyvalues.Parse(args, true)

This is also now the same code as "juju config":
func (c *configCommand) parseSet(args []string) error {
        file := c.configFile.Path != ""
        if file && len(args) > 0 {
                return errors.New("cannot specify --file and key=value arguments simultaneously")
        }
        c.action = c.setConfig
        if file {
                c.useFile = true
                return nil
        }

        settings, err := keyvalues.Parse(args, true)
        if err != nil {
                return err
        }
        c.values = settings

        return nil
}

So all of those commands strip trailing whitespace.
$ juju config mysql key=abc$'\n\n\n'
$ juju config mysql key
abc

As these are now consistent, I'm closing this bug. If there is a strong use case that we "must have trailing whitespace", then we can look to find a solution to this.

Changed in juju:
status: Triaged → Won't Fix
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.