mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
FIX: Fix ContextSummary behaviour with UTF8 chars
Fixes https://github.com/silverstripe/silverstripe-framework/issues/1396 Ensure that DBTextTest has UTF8 test cases
This commit is contained in:
parent
c942ca5be6
commit
d8b4ca91d9
@ -198,7 +198,7 @@ class DBText extends DBString
|
||||
$keywords = Convert::raw2xml($keywords);
|
||||
|
||||
// Find the search string
|
||||
$position = (int) stripos($text, $keywords);
|
||||
$position = (int) mb_stripos($text, $keywords);
|
||||
|
||||
// We want to search string to be in the middle of our block to give it some context
|
||||
$position = max(0, $position - ($characters / 2));
|
||||
@ -206,19 +206,19 @@ class DBText extends DBString
|
||||
if ($position > 0) {
|
||||
// We don't want to start mid-word
|
||||
$position = max(
|
||||
(int) strrpos(substr($text, 0, $position), ' '),
|
||||
(int) strrpos(substr($text, 0, $position), "\n")
|
||||
(int) mb_strrpos(substr($text, 0, $position), ' '),
|
||||
(int) mb_strrpos(substr($text, 0, $position), "\n")
|
||||
);
|
||||
}
|
||||
|
||||
$summary = substr($text, $position, $characters);
|
||||
$summary = mb_substr($text, $position, $characters);
|
||||
$stringPieces = explode(' ', $keywords);
|
||||
|
||||
if ($highlight) {
|
||||
// Add a span around all key words from the search term as well
|
||||
if ($stringPieces) {
|
||||
foreach ($stringPieces as $stringPiece) {
|
||||
if (strlen($stringPiece) > 2) {
|
||||
if (mb_strlen($stringPiece) > 2) {
|
||||
// Maintain case of original string
|
||||
$summary = preg_replace(
|
||||
'/' . preg_quote($stringPiece, '/') . '/i',
|
||||
|
@ -41,6 +41,7 @@ class DBTextTest extends SapphireTest
|
||||
['The little brown fox jumped over the lazy cow.', 'The little brown fox...'],
|
||||
['<p>Short & Sweet</p>', '<p>Short & Sweet</p>'],
|
||||
['This text contains & in it', 'This text contains &...'],
|
||||
['Is an umault in schön?', 'Is an umault in schö...'],
|
||||
];
|
||||
}
|
||||
|
||||
@ -80,7 +81,10 @@ class DBTextTest extends SapphireTest
|
||||
['<p>Lorem ipsum dolor sit amet</p>', 24, '<p>Lorem ipsum dolor...'],
|
||||
['<p><span>Lorem ipsum dolor sit amet</span></p>', 24, '<p><span>Lorem ipsum...'],
|
||||
['<p>Lorem ipsum</p>', 24, '<p>Lorem ipsum</p>'],
|
||||
['Lorem & ipsum dolor sit amet', 24, 'Lorem &amp; ipsum dolor...']
|
||||
['Lorem & ipsum dolor sit amet', 24, 'Lorem &amp; ipsum dolor...'],
|
||||
|
||||
['Is an umault in schön or not?', 22, 'Is an umault in schön...'],
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
@ -124,6 +128,9 @@ class DBTextTest extends SapphireTest
|
||||
// If storing HTML you should use DBHTMLText instead
|
||||
['<p>Text inside a paragraph tag should also work</p>', 3, '<p>Text inside a...'],
|
||||
['<p>Two words</p>', 3, '<p>Two words</p>'],
|
||||
|
||||
// Check UTF8
|
||||
['Is an umault in schön or not?', 5, 'Is an umault in schön...'],
|
||||
];
|
||||
}
|
||||
|
||||
@ -156,6 +163,9 @@ class DBTextTest extends SapphireTest
|
||||
// If storing HTML you should use DBHTMLText instead
|
||||
['<p>First sentence.</p>', 2, '<p>First sentence.</p>'],
|
||||
['<p>First sentence. Second sentence. Third sentence</p>', 2, '<p>First sentence. Second sentence.'],
|
||||
|
||||
// Check UTF8
|
||||
['Is schön. Isn\'t schön.', 1, 'Is schön.'],
|
||||
];
|
||||
}
|
||||
|
||||
@ -187,6 +197,9 @@ class DBTextTest extends SapphireTest
|
||||
// If storing HTML you should use DBHTMLText instead
|
||||
['<br />First sentence.', '<br />First sentence.'],
|
||||
['<p>First sentence. Second sentence. Third sentence</p>', '<p>First sentence.'],
|
||||
|
||||
// Check UTF8
|
||||
['Is schön. Isn\'t schön.', 'Is schön.'],
|
||||
];
|
||||
}
|
||||
|
||||
@ -243,7 +256,16 @@ class DBTextTest extends SapphireTest
|
||||
'ate',
|
||||
// it should highlight 3 letters or more.
|
||||
'A dog <mark>ate</mark> a cat while looking at a Foobar',
|
||||
],
|
||||
[
|
||||
'both schön and können have umlauts',
|
||||
21,
|
||||
'schön',
|
||||
// check UTF8 support
|
||||
'both <mark>schön</mark> and können...',
|
||||
]
|
||||
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user