summaryrefslogtreecommitdiff
path: root/file.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-10-16 01:53:32 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-10-16 01:53:32 +0000
commitad54de2acac70ba2f889892df950508edbc972b7 (patch)
tree2ff241b1379d08eb8382719463158e96e95a166c /file.c
parent5ed8ca14526539b31d6089a91585b9301097f380 (diff)
file.c: check_path_encoding
* file.c (check_path_encoding): new function to ensure path name encoding to be ASCII-compatible. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'file.c')
-rw-r--r--file.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/file.c b/file.c
index 38cc83b124..22df4420be 100644
--- a/file.c
+++ b/file.c
@@ -156,12 +156,22 @@ file_path_convert(VALUE name)
return name;
}
+static rb_encoding *
+check_path_encoding(VALUE str)
+{
+ rb_encoding *enc = rb_enc_get(str);
+ if (!rb_enc_asciicompat(enc)) {
+ rb_raise(rb_eEncCompatError, "path name must be ASCII-compatible (%s): %"PRIsVALUE,
+ rb_enc_name(enc), rb_str_inspect(str));
+ }
+ return enc;
+}
+
static VALUE
rb_get_path_check(VALUE obj, int level)
{
VALUE tmp;
ID to_path;
- rb_encoding *enc;
if (insecure_obj_p(obj, level)) {
rb_insecure_operation();
@@ -178,13 +188,8 @@ rb_get_path_check(VALUE obj, int level)
if (obj != tmp && insecure_obj_p(tmp, level)) {
rb_insecure_operation();
}
- enc = rb_enc_get(tmp);
- if (!rb_enc_asciicompat(enc)) {
- tmp = rb_str_inspect(tmp);
- rb_raise(rb_eEncCompatError, "path name must be ASCII-compatible (%s): %s",
- rb_enc_name(enc), RSTRING_PTR(tmp));
- }
+ check_path_encoding(tmp);
StringValueCStr(tmp);
return rb_str_new4(tmp);
@@ -3669,11 +3674,7 @@ rb_file_s_basename(int argc, VALUE *argv)
if (rb_scan_args(argc, argv, "11", &fname, &fext) == 2) {
StringValue(fext);
- enc = rb_enc_get(fext);
- if (!rb_enc_asciicompat(enc)) {
- rb_raise(rb_eEncCompatError, "ascii incompatible character encodings: %s",
- rb_enc_name(enc));
- }
+ enc = check_path_encoding(fext);
}
FilePathStringValue(fname);
if (NIL_P(fext) || !(enc = rb_enc_compatible(fname, fext))) {