whikloj / BagItTools

A PHP BagIt library
MIT License
11 stars 5 forks source link

Multiline issue on bag info tag #17

Closed henning-gerhardt closed 4 years ago

henning-gerhardt commented 4 years ago

If you are adding a bag info tag with a lot of text and this text contains at least one colon on "right" place the validation of created bag is failing. Look into this example program:

use \whikloj\BagItTools\Bag;

$dir = __DIR__ . "/newbag";

// Create new bag as directory $dir
$bag = Bag::create($dir);

// set extended on true calculate oxum value
$bag->setExtended(true);

$bag->addBagInfoTag('Title', 'A really long long long long long long long long long long long title with a colon : between and more information are on the way');

$bag->update();

if (!$bag->validate()) {
    echo 'Validation error!' . PHP_EOL;
    foreach ($bag->getErrors() as $number => $reason) {
        echo $reason['file'] .  ': ' . $reason['message'] . PHP_EOL;
    }
} else {
    echo 'Bag successful validated' . PHP_EOL;
}

Output is:

Validation error!
bag-info.txt: Labels cannot begin or end with a whitespace. (Line 2)

Content of bag-info.txt is:

Title: A really long long long long long long long long long long long title
  with a colon : between and more information are on the way
Payload-Oxum: 0.0
Bagging-Date: 2020-09-28
whikloj commented 4 years ago

Resolved with https://github.com/whikloj/BagItTools/commit/c50a0114a5f48152e3d523e91db34408cba57b27