Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
qfq
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
typo3
qfq
Commits
8ee21588
Commit
8ee21588
authored
8 years ago
by
Carsten Rose
Browse files
Options
Downloads
Patches
Plain Diff
Escape double ticks in HTML attributes in general.
Support.php: added ecapeDoubleTick()
parent
1d947296
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
extension/qfq/qfq/helper/Support.php
+23
-1
23 additions, 1 deletion
extension/qfq/qfq/helper/Support.php
extension/qfq/tests/phpunit/SupportTest.php
+41
-0
41 additions, 0 deletions
extension/qfq/tests/phpunit/SupportTest.php
with
64 additions
and
1 deletion
extension/qfq/qfq/helper/Support.php
+
23
−
1
View file @
8ee21588
...
@@ -106,7 +106,29 @@ class Support {
...
@@ -106,7 +106,29 @@ class Support {
break
;
break
;
}
}
return
$type
.
'="'
.
trim
(
$value
)
.
'" '
;
$value
=
self
::
escapeDoubleTick
(
trim
(
$value
));
return
$type
.
'="'
.
$value
.
'" '
;
}
/**
* Escapes Double Ticks ("), which are not already escaped.
*
* @param $str
* @return string
*/
public
static
function
escapeDoubleTick
(
$str
)
{
$newStr
=
''
;
for
(
$ii
=
0
;
$ii
<
strlen
(
$str
);
$ii
++
)
{
if
(
$str
[
$ii
]
===
'"'
)
{
if
(
$ii
===
0
||
$str
[
$ii
-
1
]
!=
'\\'
)
{
$newStr
.
=
'\\'
;
}
}
$newStr
.
=
$str
[
$ii
];
}
return
$newStr
;
}
}
/**
/**
...
...
This diff is collapsed.
Click to expand it.
extension/qfq/tests/phpunit/SupportTest.php
+
41
−
0
View file @
8ee21588
...
@@ -349,6 +349,47 @@ class SupportTest extends \PHPUnit_Framework_TestCase {
...
@@ -349,6 +349,47 @@ class SupportTest extends \PHPUnit_Framework_TestCase {
$this
->
assertEquals
([
'id'
=>
2
],
$new
);
$this
->
assertEquals
([
'id'
=>
2
],
$new
);
}
}
public
function
testEscapeDoubleTick
()
{
// empty string
$new
=
Support
::
escapeDoubleTick
(
''
);
$this
->
assertEquals
(
''
,
$new
);
// nothing to replace
$new
=
Support
::
escapeDoubleTick
(
'hello world'
);
$this
->
assertEquals
(
'hello world'
,
$new
);
// last word
$new
=
Support
::
escapeDoubleTick
(
'hello "world"'
);
$this
->
assertEquals
(
'hello \\"world\\"'
,
$new
);
// first word
$new
=
Support
::
escapeDoubleTick
(
'"hello" world'
);
$this
->
assertEquals
(
'\\"hello\\" world'
,
$new
);
// just "
$new
=
Support
::
escapeDoubleTick
(
'"'
);
$this
->
assertEquals
(
'\\"'
,
$new
);
// just \"
$new
=
Support
::
escapeDoubleTick
(
'\\"'
);
$this
->
assertEquals
(
'\\"'
,
$new
);
// already escaped: middle
$new
=
Support
::
escapeDoubleTick
(
'hello \\"T world'
);
$this
->
assertEquals
(
'hello \\"T world'
,
$new
);
// already escaped: start
$new
=
Support
::
escapeDoubleTick
(
'\\"T hello world'
);
$this
->
assertEquals
(
'\\"T hello world'
,
$new
);
// already escaped: end
$new
=
Support
::
escapeDoubleTick
(
'hello world \\"'
);
$this
->
assertEquals
(
'hello world \\"'
,
$new
);
}
protected
function
setUp
()
{
protected
function
setUp
()
{
parent
::
setUp
();
parent
::
setUp
();
...
...
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