Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
497c0b1c
Commit
497c0b1c
authored
Feb 27, 2009
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tag: don't accept invalid UTF-8 sequences
Overwrite invalid UTF-8 sequences with question marks.
parent
c1ab2d06
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
5 deletions
+27
-5
tag.c
src/tag.c
+27
-5
No files found.
src/tag.c
View file @
497c0b1c
...
...
@@ -407,24 +407,46 @@ bool tag_equal(const struct tag *tag1, const struct tag *tag2)
return
true
;
}
/**
* Replace invalid sequences with the question mark.
*/
static
char
*
patch_utf8
(
const
char
*
src
,
size_t
length
,
const
gchar
*
end
)
{
/* duplicate the string, and replace invalid bytes in that
buffer */
char
*
dest
=
g_strdup
(
src
);
do
{
dest
[
end
-
src
]
=
'?'
;
}
while
(
!
g_utf8_validate
(
end
+
1
,
(
src
+
length
)
-
(
end
+
1
),
&
end
));
return
dest
;
}
static
char
*
fix_utf8
(
const
char
*
str
,
size_t
length
)
{
const
gchar
*
end
;
char
*
temp
;
gsize
written
;
assert
(
str
!=
NULL
);
if
(
g_utf8_validate
(
str
,
length
,
NULL
))
/* check if the string is already valid UTF-8 */
if
(
g_utf8_validate
(
str
,
length
,
&
end
))
return
NULL
;
DEBUG
(
"not valid utf8 in tag: %s
\n
"
,
str
);
/* no, it's not - try to import it from ISO-Latin-1 */
temp
=
g_convert
(
str
,
length
,
"utf-8"
,
"iso-8859-1"
,
NULL
,
&
written
,
NULL
);
if
(
temp
==
NULL
)
return
NULL
;
if
(
temp
!=
NULL
)
/* success! */
return
temp
;
/* no, still broken - there's no medication, just patch
invalid sequences */
return
patch_utf8
(
str
,
length
,
end
);
}
void
tag_begin_add
(
struct
tag
*
tag
)
...
...
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