bentglasstube / Net-MPD

5 stars 1 forks source link

Sending undef string with {add} adds whole library #10

Open carnager opened 6 years ago

carnager commented 6 years ago

MPD protocol specifies that an empty string adds the whole library (for historical reasons "/" also works). Net::MPD on the other hand also reacts this way if a value is not initialized at all.

Code example:

#
use Data::Dumper;
use Net::MPD;
$mpd //= Net::MPD->connect($ENV{MPD_HOST} // 'localhost');
my @array=();
my $track = $array[rand @array];
my $foo = $track{uri};
$mpd->add($foo);
bentglasstube commented 6 years ago

I'm happy to change this behavior, but I'm not sure what I would change it to. What would you rather Net::MPD do with $mpd->add(undef) ?

carnager commented 6 years ago

I guess it should simply do nothing and spit a warning about not being able to add "nothing"

bentglasstube commented 6 years ago

The trouble for me is it seems a bit strange for add('') and add(undef) to behave so differently. Perhaps you could share the use case you have where add(undef) adding the entire library is problematic.

fiete201 commented 6 years ago

From my perspective undef should be treated special since it also generates these warnings: Use of uninitialized value $arg in substitution (s///) at /usr/share/perl5/Net/MPD.pm line 89, <GEN0> line 4411. Use of uninitialized value $arg in concatenation (.) or string at /usr/share/perl5/Net/MPD.pm line 90, <GEN0> line 4411. And that '' might be send by intention but undef not and the behaviour will mostly just hide/mask bugs.

Best regards Fritz

bentglasstube commented 6 years ago

That's a good argument. I will implement some argument checking against undef when I return from vacation.

fiete201 commented 6 years ago

Great thanks! And enjoy your holidays!

carnager commented 6 years ago

Just to add this input: mpc behaves the same way. If you run mpc add (which will wait for stdin) and then hit Ctrl+d, nothing will be added.