borisveytsman / crossrefware

4 stars 0 forks source link

Bug - most likely in BibTeX::Parser #11

Closed pauloney closed 6 years ago

pauloney commented 6 years ago

I think I nailed down the error:

Use of uninitialized value in concatenation (.) or string at 
/usr/local/texlive/2017/texmf-dist/scripts/bibtexperllibs/BibTeX/Parser/Author.pm line 266,
<GEN0> line 13.

that I had talked to you before and that is also the subject of Bug #3 below.

In a bibtex record of type "Junior-without-Von" the error comes up always, for example in the two records below:

@book{rec1,
    author = {Morrey, Jr, Charles B.},
    title = {Book One},
    publisher = {Spring},
    year = {2018},
}

@book{rec2,
    author = {Morrey, Neto, Charles B.},
    title = {Book Two},
    publisher = {Spring},
    year = {2018},
}

If you run bibmradd you will see the error. You will also see it with any of the other programs which make me believe the problem is in the BibTeX::Parser.

It is also introducing a spurious space at the start of the author field in the output -- right where the "von" part of a name should have been (if it existed):

@BOOK{rec1,
    author = { Morrey, Jr, Charles B.},
    title = {Book One},
    publisher = {Spring},
    year = {2018},
    mrnumber = {},
}

@BOOK{rec2,
    author = { Morrey, Neto, Charles B.},
    title = {Book Two},
    publisher = {Spring},
    year = {2018},
    mrnumber = {},
}

making it one more reason to believe that is where the problem is. The spurious space does NOT happen when the "von" part of a name is there which is even more indication that the parser is probably introducing a concatenation (.) there.

pauloney commented 6 years ago

Indeed, in:

/usr/local/share/perl/5.22.1/BibTeX/Parser/Author.pm

on line 262 in the function to make convert BibTeX::Parser::Author object to string, if jr-part is set then all four (first, von, last, jr) parts must present:

sub to_string {
       my $self = shift;

       if ($self->jr) {
               return $self->von . " " . $self->last . ", " . $self->jr . ", " . $self->first;
       } else {
               return ($self->von ? $self->von . " " : '') . $self->last . ($self->first ? ", " . $self->first : '');
       }   
}   

and the spurious concatenation (.) is left there if the name does not have a "von" part.

borisveytsman commented 6 years ago

Yes, it was a bug in the underlying library. Fixed there.

tex-apprentice commented 1 year ago

I see that the concatenation issue has been solved in this last version, but not the introduction of the space at the start of the name (when writing the record). Do you know where it comes from?

kberry commented 1 year ago

looking at Parser/Author.pm, if jr is set and von isn't, it seems the return value will start with a space. (And if von is set, there will be two spaces.) That code being:

if ($self->jr) {
                return ($self->von ? $self->von . " " : '') . " " . $self->last . ", " . $self->jr . ", " . $self->first;

Not a big deal to fix, but can you tell me how to reproduce, specifically?

pauloney commented 1 year ago

Indeed! I had not observed the case with two spaces, but it is there. The two spaces are between the "von" and the start of the "last name".

The easiest way to check is on the file:

@book{rec1, author = {Morrey, Jr., Charles B.}, title = {Book One}, publisher = {Spring}, year = {2018}, }

@book{rec2, author = {von Braun, Jr, Werner}, title = {Book Two}, publisher = {Spring}, year = {2018}, }

and then execute "bibmradd" on the file.

Paulo Ney

On Sun, Jul 3, 2022 at 2:59 PM kberry @.***> wrote:

looking at Parser/Author.pm, if jr is set and von isn't, it seems the return value will start with a space. (And if von is set, there will be two spaces.) That code being:

if ($self->jr) { return ($self->von ? $self->von . " " : '') . " " . $self->last . ", " . $self->jr . ", " . $self->first;

Not a big deal to fix, but can you tell me how to reproduce, specifically?

— Reply to this email directly, view it on GitHub https://github.com/borisveytsman/crossrefware/issues/11#issuecomment-1173178819, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAR7WYRYVGRNEHU2MD4QMMTVSIEMFANCNFSM4EU3AMBA . You are receiving this because you authored the thread.Message ID: @.***>

kberry commented 1 year ago

I committed a new version of Author.pm which I hope avoids the spurious spaces. The new to_string() fn looks like:

my $last = $self->last; # assume always present
my $first = $self->first ? (", " . $self->first) : ''; # ", first"
my $von = $self->von ? ($self->von . " ") : '';        # "von "
my $jr = $self->jr ? (", " . $self->jr ) : '';         # ", jr"
#
my $ret = "${von}${last}${jr}${first}";

The idea being to include the needed space, or comma-space, in the variable corresponding to each part, if the value is nonempty. Hope it flies ...