Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Stud.IP
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jan-Hendrik Willms
Stud.IP
Commits
ecd9256f
Commit
ecd9256f
authored
1 year ago
by
Jan-Hendrik Willms
Committed by
Elmar Ludwig
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
preserve link breaks and adjust tests, fixes #2278
Closes #2278 Merge request
studip/studip!1680
parent
29b2bb37
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/classes/Markup.class.php
+7
-0
7 additions, 0 deletions
lib/classes/Markup.class.php
tests/unit/lib/classes/MarkupClassTest.php
+42
-31
42 additions, 31 deletions
tests/unit/lib/classes/MarkupClassTest.php
with
49 additions
and
31 deletions
lib/classes/Markup.class.php
+
7
−
0
View file @
ecd9256f
...
@@ -487,6 +487,13 @@ class Markup
...
@@ -487,6 +487,13 @@ class Markup
$config
->
set
(
'HTML.Allowed'
,
'a[href],img[alt|src],br'
);
$config
->
set
(
'HTML.Allowed'
,
'a[href],img[alt|src],br'
);
$config
->
set
(
'AutoFormat.Custom'
,
[
'Unlinkify'
]);
$config
->
set
(
'AutoFormat.Custom'
,
[
'Unlinkify'
]);
$html
=
str_replace
(
'</li>'
,
'</li><br>'
,
$html
);
$html
=
str_replace
(
'</ol>'
,
'</ol><br>'
,
$html
);
$html
=
str_replace
(
'</ul>'
,
'</ul><br>'
,
$html
);
$html
=
str_replace
(
'</tr>'
,
'</tr><br>'
,
$html
);
$html
=
str_replace
(
'</p>'
,
'</p><br><br>'
,
$html
);
$html
=
str_replace
(
'</div>'
,
'</div><br><br>'
,
$html
);
$purifier
=
new
\HTMLPurifier
(
$config
);
$purifier
=
new
\HTMLPurifier
(
$config
);
$html
=
$purifier
->
purify
(
$html
);
$html
=
$purifier
->
purify
(
$html
);
...
...
This diff is collapsed.
Click to expand it.
tests/unit/lib/classes/MarkupClassTest.php
+
42
−
31
View file @
ecd9256f
...
@@ -50,40 +50,14 @@ class Seminar_Session
...
@@ -50,40 +50,14 @@ class Seminar_Session
*/
*/
class
MarkupClassTest
extends
\Codeception\Test\Unit
class
MarkupClassTest
extends
\Codeception\Test\Unit
{
{
public
function
testRemoveHTML
()
/**
* @dataProvider removeProvider
*/
public
function
testRemoveHTML
(
string
$input
,
string
$expected
):
void
{
{
Config
::
set
(
new
Config
([
'WYSIWYG'
=>
true
]));
Config
::
set
(
new
Config
([
'WYSIWYG'
=>
true
]));
foreach
([
$this
->
assertEquals
(
$expected
,
Studip\Markup
::
removeHtml
(
Studip\Markup
::
markAsHtml
(
$input
)));
'plain text'
=>
'plain text'
,
'<p>paragraph only</p>'
=>
'paragraph only'
,
'<a>no href</a>'
=>
'no href'
,
'<a href=""></a>'
=>
''
,
'<a href="">empty href</a>'
=>
'empty href'
,
'<a href="href only" />'
=>
'[ href%20only ]'
,
'<a href="href end-tag"></a>'
=>
'[ href%20end-tag ]'
,
'<a href="http://href.de">and text</a>'
=>
'[ http://href.de ]and text'
,
'before <a href="http://href.de">and text</a> after'
=>
'before [ http://href.de ]and text after'
,
'<img>no src</img>'
=>
'no src'
,
'<img src="src only" />'
=>
'[ src%20only ]'
,
'<img src="src end-tag"></img>'
=>
'[ src%20end-tag ]'
,
'<img src="http://src.de">and text</a>'
=>
'[ http://src.de ]and text'
,
'before <img src="http://src.de">and text</img> after'
=>
'before [ http://src.de ]and text after'
,
// some "real" urls
'<a href="https://example.org/">Example'
=>
'[ https://example.org/ ]Example'
,
'<img src="https://example.org/image.png">'
=>
'[ https://example.org/image.png ]'
,
'<p>link <a href="http://example.org">Example-Domain</a> and picture <img src="https://example.org/image.png"></p>'
=>
'link [ http://example.org ]Example-Domain and picture [ https://example.org/image.png ]'
]
as
$in
=>
$out
)
{
$this
->
assertEquals
(
$out
,
Studip\Markup
::
removeHtml
(
Studip\Markup
::
markAsHtml
(
$in
)));
}
}
}
public
function
testGetMediaUrl
()
public
function
testGetMediaUrl
()
...
@@ -223,4 +197,41 @@ class MarkupClassTest extends \Codeception\Test\Unit
...
@@ -223,4 +197,41 @@ class MarkupClassTest extends \Codeception\Test\Unit
}
}
}
}
}
}
public
static
function
removeProvider
():
array
{
return
[
'plain text'
=>
[
'plain text'
,
'plain text'
],
'paragraph only'
=>
[
'<p>paragraph only</p>'
,
'paragraph only'
],
'link: no href'
=>
[
'<a>no href</a>'
,
'no href'
],
'link: empty'
=>
[
'<a href=""></a>'
,
''
],
'link: empty href'
=>
[
'<a href="">empty href</a>'
,
'empty href'
],
'link: href only'
=>
[
'<a href="href only" />'
,
'[ href%20only ]'
],
'link: href end-tag'
=>
[
'<a href="href end-tag"></a>'
,
'[ href%20end-tag ]'
],
'link: href and text'
=>
[
'<a href="http://href.de">and text</a>'
,
'[ http://href.de ]and text'
],
'link: before and text after'
=>
[
'before <a href="http://href.de">and text</a> after'
,
'before [ http://href.de ]and text after'
],
'image: no src'
=>
[
'<img>no src</img>'
,
'no src'
],
'image: src only'
=>
[
'<img src="src only" />'
,
'[ src%20only ]'
],
'image: src end-tag'
=>
[
'<img src="src end-tag"></img>'
,
'[ src%20end-tag ]'
],
'image: src and text'
=>
[
'<img src="http://src.de">and text</a>'
,
'[ http://src.de ]and text'
],
'image: before and text after'
=>
[
'before <img src="http://src.de">and text</img> after'
,
'before [ http://src.de ]and text after'
],
// some "real" urls
'real link'
=>
[
'<a href="https://example.org/">Example'
,
'[ https://example.org/ ]Example'
],
'real image'
=>
[
'<img src="https://example.org/image.png">'
,
'[ https://example.org/image.png ]'
],
'real link and image'
=>
[
'<p>link <a href="http://example.org">Example-Domain</a> and picture <img src="https://example.org/image.png"></p>'
,
'link [ http://example.org ]Example-Domain and picture [ https://example.org/image.png ]'
,
],
// Line breaks
'html: ul'
=>
[
\Studip\Markup
::
HTML_MARKER
.
'<ul><li>1</li><li>2</li></ul><p>3</p>'
,
"1
\n
2
\n\n
3"
],
'html: ol'
=>
[
\Studip\Markup
::
HTML_MARKER
.
'<ol><li>1</li><li>2</li></ol><p>3</p>'
,
"1
\n
2
\n\n
3"
],
'html: br'
=>
[
\Studip\Markup
::
HTML_MARKER
.
'1<br>2<br>3'
,
"1
\n
2
\n
3"
],
'html: div'
=>
[
\Studip\Markup
::
HTML_MARKER
.
'<div>1</div><div>2</div><div>3</div>'
,
"1
\n\n
2
\n\n
3"
],
'html: p'
=>
[
\Studip\Markup
::
HTML_MARKER
.
'<p>1</p><p>2</p><p>3</p>'
,
"1
\n\n
2
\n\n
3"
],
];
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment