Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/writers/Oaipmh.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ public function writeMetadataFile($metadata, $path, $overwrite = true)
public function normalizeFilename($string)
{
$string = urldecode($string);
$pattern = '#'.DIRECTORY_SEPARATOR.'#';

@mjordan mjordan Jul 19, 2017

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We run MIK on Windows, and since DIRECTORY_SEPARATOR on Windows is \, we've been burned using DIRECTORY_SEPARATOR unless the pattern is run through PHP's preg_quote(), since \ is also an escape character in regexes. So I recommend, and have used, something like this:

$pattern = preg_quote('#' . DIRECTORY_SEPARATOR . '#');

I can test with that code if you want, report back, and if it works on Windows and Linux, I'll merge.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds great.

@mjordan mjordan Jul 19, 2017

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit more end-of-the-day hacking around has produced:

    /**
     * Convert %3A (:) and other characters in filenames into underscores (_).
     */
    public function normalizeFilename($string)
    {
        $string = urldecode($string);
        $bad_chars = [
            ':' => '_',
            DIRECTORY_SEPARATOR => '_',
        ];
        $string = str_replace(array_keys($bad_chars), $bad_chars, $string);
        return $string;
    }

This replaces : in my local tests. Could you test to see if it catches the directory separator? The benefit of str_replace() is that you don't need to worry about nasty cross-platform issues (I hope). Also adding new bad characters is pretty easy.

$string = preg_replace($pattern, '-', $string);
$string = preg_replace('/:/', '_', $string);
return $string;
}
Expand Down