Skip to content

Commit 47e3baa

Browse files
authored
Merge pull request #54 from shaarli/fix/keep-tab-characters
Do not replace tab characters
2 parents 407171f + 6dbb72a commit 47e3baa

File tree

4 files changed

+76
-3
lines changed

4 files changed

+76
-3
lines changed

NetscapeBookmarkParser.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,15 +321,15 @@ public static function sanitizeString($bookmarkString)
321321
// trim whitespace
322322
$sanitized = trim($sanitized);
323323

324-
// trim carriage returns, replace tabs by a single space
325-
$sanitized = str_replace(array("\r", "\t"), array('',' '), $sanitized);
324+
// trim carriage returns
325+
$sanitized = str_replace("\r", '', $sanitized);
326326

327327
// convert multiline descriptions to one-line descriptions
328328
// line feeds are converted to <br>
329329
$sanitized = preg_replace_callback(
330330
'@<DD>(.*?)(</?(:?DT|DD|DL))@mis',
331331
function($match) {
332-
return '<DD>'.str_replace("\n", '<br>', trim($match[1])).PHP_EOL. $match[2];
332+
return '<DD>'.str_replace("\n", '<br>', trim($match[1])).PHP_EOL. $match[2];
333333
},
334334
$sanitized
335335
);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Shaarli\NetscapeBookmarkParser;
4+
5+
class ParseShaarliWithTabsAndSpacesTest extends \PHPUnit_Framework_TestCase
6+
{
7+
/**
8+
* Delete log file.
9+
*/
10+
public function tearDown()
11+
{
12+
@unlink(LoggerTestsUtils::getLogFile());
13+
}
14+
15+
/**
16+
* Parse flat Chromium bookmarks (no directories)
17+
*/
18+
public function testParseFlat()
19+
{
20+
$parser = new NetscapeBookmarkParser(false, null, '1');
21+
$bkm = $parser->parseFile('tests/input/shaarli_with_tabs_and_spaces.htm');
22+
23+
static::assertSame(
24+
trim(file_get_contents('tests/output/shaarli_with_tabs_and_spaces.txt')),
25+
$bkm[0]['note']
26+
);
27+
}
28+
}

tests/input/shaarli_with_tabs_and_spaces.htm

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
I will write some formating using spaces:
2+
3+
* For example,
4+
* lists,
5+
+ but also
6+
+ sublists
7+
* use spaces.
8+
9+
Also code:
10+
11+
```
12+
foreach ($data['linksToDisplay'] as $key => $bookmark) {
13+
$length = strlen($bookmark['title']) + (342 * strlen($bookmark['description'])) / 836;
14+
if (! empty($bookmark['thumbnail'])) {
15+
$length += 100; // 1 thumbnails roughly takes 100 pixels height.
16+
}
17+
}
18+
```

0 commit comments

Comments
 (0)