Fix a bug when using '/' as a tag separator (#1953)
This commit is contained in:
parent
8457001294
commit
b858332f9f
2 changed files with 21 additions and 2 deletions
|
@ -217,9 +217,9 @@ function is_note($linkUrl)
|
||||||
function tags_str2array(?string $tags, string $separator): array
|
function tags_str2array(?string $tags, string $separator): array
|
||||||
{
|
{
|
||||||
// For whitespaces, we use the special \s regex character
|
// For whitespaces, we use the special \s regex character
|
||||||
$separator = $separator === ' ' ? '\s' : $separator;
|
$separator = str_replace([' ', '/'], ['\s', '\/'], $separator);
|
||||||
|
|
||||||
return preg_split('/\s*' . $separator . '+\s*/', trim($tags ?? ''), -1, PREG_SPLIT_NO_EMPTY);
|
return preg_split('/\s*' . $separator . '+\s*/', trim($tags ?? ''), -1, PREG_SPLIT_NO_EMPTY) ?: [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -652,6 +652,25 @@ public function testTagsStr2ArrayWithCharSeparator(): void
|
||||||
static::assertSame([], tags_str2array(null, $separator));
|
static::assertSame([], tags_str2array(null, $separator));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test tags_str2array with / separator.
|
||||||
|
*/
|
||||||
|
public function testTagsStr2ArrayWithRegexDelimiterSeparator(): void
|
||||||
|
{
|
||||||
|
$separator = '/';
|
||||||
|
|
||||||
|
static::assertSame(['tag1', 'tag2', 'tag3'], tags_str2array('tag1/tag2/tag3', $separator));
|
||||||
|
static::assertSame(['tag1', 'tag2', 'tag3'], tags_str2array('tag1////tag2////tag3', $separator));
|
||||||
|
static::assertSame(['tag1', 'tag2', 'tag3'], tags_str2array('///tag1///tag2////tag3//', $separator));
|
||||||
|
static::assertSame(
|
||||||
|
['tag1#', 'tag2, and other', '.tag3'],
|
||||||
|
tags_str2array('/// tag1# /// tag2, and other ////.tag3//', $separator)
|
||||||
|
);
|
||||||
|
static::assertSame([], tags_str2array('', $separator));
|
||||||
|
static::assertSame([], tags_str2array(' ', $separator));
|
||||||
|
static::assertSame([], tags_str2array(null, $separator));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test tags_array2str with ' ' separator.
|
* Test tags_array2str with ' ' separator.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue