Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc
Commits
15c5e826
Commit
15c5e826
authored
May 05, 2011
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
XML: encode C0/C1 control codes correctly (fix #4737)
parent
8bea8642
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
25 deletions
+37
-25
src/text/strings.c
src/text/strings.c
+37
-25
No files found.
src/text/strings.c
View file @
15c5e826
...
@@ -47,6 +47,8 @@
...
@@ -47,6 +47,8 @@
#include <vlc_strings.h>
#include <vlc_strings.h>
#include <vlc_url.h>
#include <vlc_url.h>
#include <vlc_charset.h>
#include <vlc_charset.h>
#include <libvlc.h>
#include <errno.h>
/**
/**
* Decode encoded URI component. See also decode_URI().
* Decode encoded URI component. See also decode_URI().
...
@@ -392,41 +394,51 @@ void resolve_xml_special_chars( char *psz_value )
...
@@ -392,41 +394,51 @@ void resolve_xml_special_chars( char *psz_value )
}
}
/**
/**
* Converts '<', '>', '\"', '\'' and '&' to their html entities
* XML-encode an UTF-8 string
* \param psz_content simple element content that is to be converted
* \param str nul-terminated UTF-8 byte sequence to XML-encode
* \return XML encoded string or NULL on error
* (errno is set to ENOMEM or EILSEQ as appropriate)
*/
*/
char
*
convert_xml_special_chars
(
const
char
*
psz_content
)
char
*
convert_xml_special_chars
(
const
char
*
str
)
{
{
assert
(
psz_content
);
assert
(
str
!=
NULL
);
const
size_t
len
=
strlen
(
psz_content
);
const
size_t
len
=
strlen
(
str
);
char
*
const
psz_temp
=
malloc
(
6
*
len
+
1
);
char
*
const
buf
=
malloc
(
6
*
len
+
1
),
*
ptr
=
buf
;
char
*
p_to
=
psz_temp
;
if
(
unlikely
(
buf
==
NULL
))
if
(
psz_temp
==
NULL
)
return
NULL
;
return
NULL
;
for
(
size_t
i
=
0
;
i
<
len
;
i
++
)
size_t
n
;
uint32_t
cp
;
while
((
n
=
vlc_towc
(
str
,
&
cp
))
!=
0
)
{
{
const
char
*
str
;
if
(
unlikely
(
n
==
(
size_t
)
-
1
))
char
c
=
psz_content
[
i
];
{
free
(
buf
);
errno
=
EILSEQ
;
return
NULL
;
}
switch
(
c
)
if
((
cp
&
~
0x0080
)
<
32
/* C0/C1 control codes */
&&
strchr
(
"
\x09\x0A\x0D\x85
"
,
cp
)
==
NULL
)
ptr
+=
sprintf
(
ptr
,
"&#%"
PRIu32
";"
,
cp
);
else
switch
(
cp
)
{
{
case
'\"'
:
str
=
"quot"
;
break
;
case
'\"'
:
strcpy
(
ptr
,
"""
);
ptr
+=
6
;
break
;
case
'&'
:
str
=
"amp"
;
break
;
case
'&'
:
strcpy
(
ptr
,
"&"
);
ptr
+=
5
;
break
;
case
'\''
:
str
=
"#39"
;
break
;
case
'\''
:
strcpy
(
ptr
,
"'"
);
ptr
+=
5
;
break
;
case
'<'
:
str
=
"lt"
;
break
;
case
'<'
:
strcpy
(
ptr
,
"<"
);
ptr
+=
4
;
break
;
case
'>'
:
str
=
"gt"
;
break
;
case
'>'
:
strcpy
(
ptr
,
">"
);
ptr
+=
4
;
break
;
default:
default:
memcpy
(
ptr
,
str
,
n
);
ptr
+=
n
;
break
;
*
(
p_to
++
)
=
c
;
continue
;
}
}
p_to
+=
sprintf
(
p_to
,
"&%s;"
,
str
)
;
str
+=
n
;
}
}
*
(
p
_to
++
)
=
'\0'
;
*
(
p
tr
++
)
=
'\0'
;
p
_to
=
realloc
(
psz_temp
,
p_to
-
psz_temp
);
p
tr
=
realloc
(
buf
,
ptr
-
buf
);
return
p_to
?
p_to
:
psz_temp
;
/* cannot fail */
return
likely
(
ptr
!=
NULL
)
?
ptr
:
buf
;
/* cannot fail */
}
}
/* Base64 encoding */
/* Base64 encoding */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment