Skip to content
Snippets Groups Projects
Commit 449bad39 authored by Christopher Smith's avatar Christopher Smith
Browse files

Merge pull request #241 from splitbrain/FS#2770

FS#2770 - prevent <file> and <code> syntax regex matching too much
parents 15754217 fdd9bab6
No related branches found
No related tags found
No related merge requests found
<?php
require_once 'parser.inc.php';
class TestOfDoku_Parser_Code extends TestOfDoku_Parser {
function setUp() {
parent::setUp();
$this->P->addMode('code',new Doku_Parser_Mode_Code());
}
function testCode() {
$this->P->parse('Foo <code>Test</code> Bar');
$calls = array (
array('document_start',array()),
array('p_open',array()),
array('cdata',array("\n".'Foo ')),
array('p_close',array()),
array('code',array('Test',null,null)),
array('p_open',array()),
array('cdata',array(' Bar')),
array('p_close',array()),
array('document_end',array()),
);
$this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
}
function testCodeBash() {
$this->P->parse('Foo <code bash>Test</code> Bar');
$calls = array (
array('document_start',array()),
array('p_open',array()),
array('cdata',array("\n".'Foo ')),
array('p_close',array()),
array('code',array('Test','bash',null)),
array('p_open',array()),
array('cdata',array(' Bar')),
array('p_close',array()),
array('document_end',array()),
);
$this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
}
function testCodeDownload() {
$this->P->parse('Foo <code bash script.sh>Test</code> Bar');
$calls = array (
array('document_start',array()),
array('p_open',array()),
array('cdata',array("\n".'Foo ')),
array('p_close',array()),
array('code',array('Test','bash','script.sh')),
array('p_open',array()),
array('cdata',array(' Bar')),
array('p_close',array()),
array('document_end',array()),
);
$this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
}
function testCodeToken() {
$this->P->parse('Foo <code2>Bar</code2><code>Test</code>');
$calls = array (
array('document_start',array()),
array('p_open',array()),
array('cdata',array("\n".'Foo <code2>Bar</code2>')),
array('p_close',array()),
array('code',array('Test',null,null)),
array('document_end',array()),
);
$this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
}
}
<?php
require_once 'parser.inc.php';
class TestOfDoku_Parser_File extends TestOfDoku_Parser {
function setUp() {
parent::setUp();
$this->P->addMode('file',new Doku_Parser_Mode_File());
}
function testFile() {
$this->P->parse('Foo <file>Test</file> Bar');
$calls = array (
array('document_start',array()),
array('p_open',array()),
array('cdata',array("\n".'Foo ')),
array('p_close',array()),
array('file',array('Test',null,null)),
array('p_open',array()),
array('cdata',array(' Bar')),
array('p_close',array()),
array('document_end',array()),
);
$this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
}
function testFileHighlightDownload() {
$this->P->parse('Foo <file txt test.txt>Test</file> Bar');
$calls = array (
array('document_start',array()),
array('p_open',array()),
array('cdata',array("\n".'Foo ')),
array('p_close',array()),
array('file',array('Test','txt','test.txt')),
array('p_open',array()),
array('cdata',array(' Bar')),
array('p_close',array()),
array('document_end',array()),
);
$this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
}
function testFileToken() {
$this->P->parse('Foo <file2>Test</file2> Bar');
$calls = array (
array('document_start',array()),
array('p_open',array()),
array('cdata',array("\n".'Foo <file2>Test</file2> Bar')),
array('p_close',array()),
array('document_end',array()),
);
$this->assertEquals(array_map('stripbyteindex',$this->H->calls),$calls);
}
}
......@@ -555,7 +555,7 @@ class Doku_Parser_Mode_preformatted extends Doku_Parser_Mode {
class Doku_Parser_Mode_code extends Doku_Parser_Mode {
function connectTo($mode) {
$this->Lexer->addEntryPattern('<code(?=.*</code>)',$mode,'code');
$this->Lexer->addEntryPattern('<code\b(?=.*</code>)',$mode,'code');
}
function postConnect() {
......@@ -571,7 +571,7 @@ class Doku_Parser_Mode_code extends Doku_Parser_Mode {
class Doku_Parser_Mode_file extends Doku_Parser_Mode {
function connectTo($mode) {
$this->Lexer->addEntryPattern('<file(?=.*</file>)',$mode,'file');
$this->Lexer->addEntryPattern('<file\b(?=.*</file>)',$mode,'file');
}
function postConnect() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment