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
ba936558
Commit
ba936558
authored
Sep 27, 2008
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
encode_URI_component: fix and cleanup
parent
321e0a5a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
28 deletions
+23
-28
src/text/strings.c
src/text/strings.c
+23
-28
No files found.
src/text/strings.c
View file @
ba936558
...
...
@@ -184,57 +184,52 @@ void decode_URI( char *psz )
EnsureUTF8
(
psz
);
}
static
inline
int
isurl
safe
(
int
c
)
static
inline
bool
isuri
safe
(
int
c
)
{
/* These are the _unreserved_ URI characters (RFC3986 §2.3) */
return
(
(
unsigned
char
)(
c
-
'a'
)
<
26
)
||
(
(
unsigned
char
)(
c
-
'A'
)
<
26
)
||
(
(
unsigned
char
)(
c
-
'0'
)
<
10
)
/* Hmm, we should not encode character that are allowed in URLs
* (even if they are not URL-safe), nor URL-safe characters.
* We still encode some of them because of Microsoft's crap browser.
*/
||
(
strchr
(
"-_."
,
c
)
!=
NULL
);
}
static
inline
char
url_hexchar
(
int
c
)
{
return
(
c
<
10
)
?
c
+
'0'
:
c
+
'A'
-
10
;
||
(
strchr
(
"-._~"
,
c
)
!=
NULL
);
}
/**
* encode_URI_component
* Encodes an URI component.
* Encodes an URI component (RFC3986 §2).
*
* @param psz_ur
l
nul-terminated UTF-8 representation of the component.
* @param psz_ur
i
nul-terminated UTF-8 representation of the component.
* Obviously, you can't pass an URI containing a nul character, but you don't
* want to do that, do you?
*
* @return encoded string (must be free()'d)
* @return encoded string (must be free()'d)
, or NULL for ENOMEM.
*/
char
*
encode_URI_component
(
const
char
*
psz_ur
l
)
char
*
encode_URI_component
(
const
char
*
psz_ur
i
)
{
char
psz_enc
[
3
*
strlen
(
psz_url
)
+
1
],
*
out
=
psz_enc
;
const
uint8_t
*
in
;
char
*
psz_enc
=
malloc
((
3
*
strlen
(
psz_uri
))
+
1
),
*
out
=
psz_enc
;
for
(
in
=
(
const
uint8_t
*
)
psz_url
;
*
in
;
in
++
)
if
(
psz_enc
==
NULL
)
return
NULL
;
while
(
*
psz_uri
)
{
uint8_t
c
=
*
in
;
static
const
char
hex
[
16
]
=
"0123456789ABCDEF"
;
uint8_t
c
=
*
psz_uri
;
if
(
isurlsafe
(
c
)
)
*
out
++
=
(
char
)
c
;
else
if
(
c
==
' '
)
*
out
++
=
'+'
;
if
(
isurisafe
(
c
)
)
*
out
++
=
c
;
/* This is URI encoding, not HTTP forms:
* Space is encoded as '%20', not '+'. */
else
{
*
out
++
=
'%'
;
*
out
++
=
url_hexchar
(
c
>>
4
)
;
*
out
++
=
url_hexchar
(
c
&
0xf
)
;
*
out
++
=
hex
[
c
>>
4
]
;
*
out
++
=
hex
[
c
&
0xf
]
;
}
psz_uri
++
;
}
*
out
++
=
'\0'
;
return
strdup
(
psz_enc
);
out
=
realloc
(
psz_enc
,
out
-
psz_enc
);
return
out
?
out
:
psz_enc
;
/* realloc() can fail (safe) */
}
static
const
struct
xml_entity_s
...
...
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