diff options
author | Andreas Gohr <andi@splitbrain.org> | 2018-05-17 09:13:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-17 09:13:28 +0200 |
commit | c966fcfeb5e25c50f7028f120074ce18fd72ea3d (patch) | |
tree | f472e894efd35803e441acef0c1e94dc93736e2d | |
parent | d6cf40c315f4927548ec4d3e0b020f5642756791 (diff) | |
parent | 2ef8deb5b95403827f6d2bb6bb1122a86d36a7dc (diff) | |
download | dokuwiki-c966fcfeb5e25c50f7028f120074ce18fd72ea3d.tar.gz dokuwiki-c966fcfeb5e25c50f7028f120074ce18fd72ea3d.zip |
Merge pull request #2390 from splitbrain/footnote_metafix
Fix for Issue#1250 Footnotes break metadata abstract saving
-rw-r--r-- | _test/tests/inc/parser/renderer_metadata.test.php | 47 | ||||
-rw-r--r-- | inc/parser/metadata.php | 19 |
2 files changed, 61 insertions, 5 deletions
diff --git a/_test/tests/inc/parser/renderer_metadata.test.php b/_test/tests/inc/parser/renderer_metadata.test.php new file mode 100644 index 000000000..5498d6f1f --- /dev/null +++ b/_test/tests/inc/parser/renderer_metadata.test.php @@ -0,0 +1,47 @@ +<?php + +/** + * Class renderer_xhtml_test + */ +class renderer_metadata_test extends DokuWikiTest { + /** @var Doku_Renderer_xhtml */ + protected $R; + + /** + * Called for each test + * + * @throws Exception + */ + function setUp() { + parent::setUp(); + $this->R = new Doku_Renderer_metadata(); + } + + function tearDown() { + unset($this->R); + } + + + function test_footnote_and_abstract() { + // avoid issues with the filectime() & filemtime in document_start() & document_end() + $now = time(); + $this->R->persistent['date']['created'] = $now; + $this->R->persistent['date']['modified'] = $now; + + $this->R->document_start(); + + $this->R->cdata("abstract: "); + + $this->R->footnote_open(); + $this->R->cdata(str_pad("footnote: ", Doku_Renderer_metadata::ABSTRACT_MAX, "lotsa junk ")); + $this->R->footnote_close(); + + $this->R->cdata("abstract end."); + + $this->R->document_end(); + + $expected = 'abstract: abstract end.'; + $this->assertEquals($expected, $this->R->meta['description']['abstract']); + } + +} diff --git a/inc/parser/metadata.php b/inc/parser/metadata.php index 9b1b5c98b..f9e05bd81 100644 --- a/inc/parser/metadata.php +++ b/inc/parser/metadata.php @@ -47,6 +47,9 @@ class Doku_Renderer_metadata extends Doku_Renderer { /** @var string keeps the first image reference */ protected $firstimage = ''; + /** @var bool whether or not data is being captured for the abstract, public to be accessible by plugins */ + public $capturing = true; + /** @var bool determines if enough data for the abstract was collected, yet */ public $capture = true; @@ -123,7 +126,7 @@ class Doku_Renderer_metadata extends Doku_Renderer { * @param $text */ function cdata($text) { - if(!$this->capture) return; + if(!$this->capture || !$this->capturing) return; $this->doc .= $text; @@ -211,23 +214,29 @@ class Doku_Renderer_metadata extends Doku_Renderer { */ function footnote_open() { if($this->capture) { - // move current content to store and record footnote + // move current content to store + // this is required to ensure safe behaviour of plugins accessed within footnotes $this->store = $this->doc; $this->doc = ''; + + // disable capturing + $this->capturing = false; } } /** * Callback for footnote end syntax * - * All rendered content is moved to the $footnotes array and the old - * content is restored from $store again + * All content rendered whilst within footnote syntax mode is discarded, + * the previously rendered content is restored and capturing is re-enabled. * * @author Andreas Gohr */ function footnote_close() { if($this->capture) { - // restore old content + // re-enable capturing + $this->capturing = true; + // restore previously rendered content $this->doc = $this->store; $this->store = ''; } |