Skip to content

Commit

Permalink
Merge pull request #1771 from splitbrain/blanktitles
Browse files Browse the repository at this point in the history
fix problems with header that look falsy. fixes #1770
  • Loading branch information
splitbrain committed Feb 3, 2017
2 parents 77cd130 + 6506eaa commit 35284e8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
22 changes: 22 additions & 0 deletions _test/tests/inc/parser/renderer_xhtml.test.php
Expand Up @@ -248,4 +248,26 @@ function test_ulist() {
';
$this->assertEquals($expected, $this->R->doc);
}

public function test_blankHeader() {
$this->R->header('0', 1, 1);
$expected = '<h1 class="sectionedit1" id="section0">0</h1>';
$this->assertEquals($expected, trim($this->R->doc));
}

public function test_blankTitleLink() {
global $conf;
$id = 'blanktest';

$conf['useheading'] = 1;
saveWikiText($id,'====== 0 ======', 'test');
$this->assertTrue(page_exists($id));

$header = p_get_first_heading($id, METADATA_RENDER_UNLIMITED);
$this->assertSame('0', $header);

$this->R->internallink($id);
$expected = '<a href="/./doku.php?id='.$id.'" class="wikilink1" title="'.$id.'">0</a>';
$this->assertEquals($expected, trim($this->R->doc));
}
}
1 change: 1 addition & 0 deletions inc/confutils.php
Expand Up @@ -309,6 +309,7 @@ function actionOK($action){
*/
function useHeading($linktype) {
static $useHeading = null;
if(defined('DOKU_UNITTEST')) $useHeading = null; // don't cache during unit tests

if (is_null($useHeading)) {
global $conf;
Expand Down
4 changes: 2 additions & 2 deletions inc/parser/xhtml.php
Expand Up @@ -191,7 +191,7 @@ function toc_additem($id, $text, $level) {
function header($text, $level, $pos) {
global $conf;

if(!$text) return; //skip empty headlines
if(blank($text)) return; //skip empty headlines

$hid = $this->_headerToLink($text, true);

Expand Down Expand Up @@ -1702,7 +1702,7 @@ function _getLinkTitle($title, $default, &$isImage, $id = null, $linktype = 'con
} elseif(is_null($title) || trim($title) == '') {
if(useHeading($linktype) && $id) {
$heading = p_get_first_heading($id);
if($heading) {
if(!blank($heading)) {
return $this->_xmlEntities($heading);
}
}
Expand Down

0 comments on commit 35284e8

Please sign in to comment.