package init

This commit is contained in:
jackie_wu 2020-08-18 16:42:18 +08:00
parent 09e708305c
commit 246c4363d3
5 changed files with 230 additions and 0 deletions

BIN
idn-0.0.2.gem Normal file

Binary file not shown.

View File

@ -0,0 +1,140 @@
diff -Nrup ext.bad/idna.c ext/idna.c
--- ext.bad/idna.c 2012-02-13 22:16:33.792135714 -0500
+++ ext/idna.c 2012-02-13 23:14:43.562413759 -0500
@@ -24,6 +24,16 @@
#include <idna.h>
#include "idn.h"
+#include <ruby/encoding.h>
+
+#define ENCODED_STR_NEW2(str, encoding) \
+ ({ \
+ VALUE _string = rb_str_new2((const char *)str); \
+ int _enc = rb_enc_find_index(encoding); \
+ rb_enc_associate_index(_string, _enc); \
+ _string; \
+ })
+
/*
* Document-class: IDN::Idna
* The Idna module of LibIDN Ruby Bindings.
@@ -85,7 +95,7 @@ static VALUE toASCII(int argc, VALUE arg
flags = 0x0000;
}
- rc = idna_to_ascii_8z(RSTRING(str)->ptr, &buf, flags);
+ rc = idna_to_ascii_8z(RSTRING_PTR(str), &buf, flags);
if (rc != IDNA_SUCCESS) {
xfree(buf);
@@ -93,7 +103,7 @@ static VALUE toASCII(int argc, VALUE arg
return Qnil;
}
- retv = rb_str_new2(buf);
+ retv = ENCODED_STR_NEW2(buf, "ASCII-8BIT");
xfree(buf);
return retv;
}
@@ -125,7 +135,7 @@ static VALUE toUnicode(int argc, VALUE a
flags = 0x0000;
}
- rc = idna_to_unicode_8z8z(RSTRING(str)->ptr, &buf, flags);
+ rc = idna_to_unicode_8z8z(RSTRING_PTR(str), &buf, flags);
if (rc != IDNA_SUCCESS) {
xfree(buf);
@@ -133,7 +143,7 @@ static VALUE toUnicode(int argc, VALUE a
return Qnil;
}
- retv = rb_str_new2(buf);
+ retv = ENCODED_STR_NEW2(buf, "UTF-8");
xfree(buf);
return retv;
}
diff -Nrup ext.bad/punycode.c ext/punycode.c
--- ext.bad/punycode.c 2012-02-13 22:16:33.792135714 -0500
+++ ext/punycode.c 2012-02-13 23:19:39.499714035 -0500
@@ -26,6 +26,14 @@
#include <punycode.h>
#include "idn.h"
+#define ENCODED_STR_NEW(str, len, encoding) \
+ ({ \
+ VALUE _string = rb_str_new((const char *)str, (long)len); \
+ int _enc = rb_enc_find_index(encoding); \
+ rb_enc_associate_index(_string, _enc); \
+ _string; \
+ })
+
/*
* Document-class: IDN::Punycode
* The Punycode module of LibIDN Ruby Bindings.
@@ -66,7 +74,7 @@ static VALUE encode(VALUE self, VALUE st
VALUE retv;
str = rb_check_convert_type(str, T_STRING, "String", "to_s");
- ustr = stringprep_utf8_to_ucs4(RSTRING(str)->ptr, RSTRING(str)->len, &len);
+ ustr = stringprep_utf8_to_ucs4(RSTRING_PTR(str), RSTRING_LEN(str), &len);
while (1) {
buf = realloc(buf, buflen);
@@ -116,7 +124,7 @@ static VALUE decode(VALUE self, VALUE st
str = rb_check_convert_type(str, T_STRING, "String", "to_s");
- len = RSTRING(str)->len;
+ len = RSTRING_LEN(str);
ustr = malloc(len * sizeof(punycode_uint));
if (ustr == NULL) {
@@ -124,7 +132,7 @@ static VALUE decode(VALUE self, VALUE st
return Qnil;
}
- rc = punycode_decode(RSTRING(str)->len, RSTRING(str)->ptr,
+ rc = punycode_decode(RSTRING_LEN(str), RSTRING_PTR(str),
&len, ustr, NULL);
if (rc != PUNYCODE_SUCCESS) {
@@ -134,7 +142,7 @@ static VALUE decode(VALUE self, VALUE st
}
buf = stringprep_ucs4_to_utf8(ustr, len, NULL, &len);
- retv = rb_str_new(buf, len);
+ retv = ENCODED_STR_NEW(buf, len, "UTF-8");
xfree(ustr);
xfree(buf);
return retv;
diff -Nrup ext.bad/stringprep.c ext/stringprep.c
--- ext.bad/stringprep.c 2012-02-13 22:16:33.792135714 -0500
+++ ext/stringprep.c 2012-02-13 22:16:55.618862844 -0500
@@ -64,7 +64,7 @@ static VALUE stringprep_internal(VALUE s
VALUE retv;
str = rb_check_convert_type(str, T_STRING, "String", "to_s");
- rc = stringprep_profile(RSTRING(str)->ptr, &buf, profile, 0);
+ rc = stringprep_profile(RSTRING_PTR(str), &buf, profile, 0);
if (rc != STRINGPREP_OK) {
rb_raise(eStringprepError, "%s (%d)", stringprep_strerror(rc), rc);
@@ -135,7 +135,7 @@ static VALUE resourceprep(VALUE self, VA
static VALUE with_profile(VALUE self, VALUE str, VALUE profile)
{
profile = rb_check_convert_type(profile, T_STRING, "String", "to_s");
- return stringprep_internal(str, RSTRING(profile)->ptr);
+ return stringprep_internal(str, RSTRING_PTR(profile));
}
/*
@@ -153,7 +153,7 @@ static VALUE nfkc_normalize(VALUE self,
VALUE retv;
str = rb_check_convert_type(str, T_STRING, "String", "to_s");
- buf = stringprep_utf8_nfkc_normalize(RSTRING(str)->ptr, RSTRING(str)->len);
+ buf = stringprep_utf8_nfkc_normalize(RSTRING_PTR(str), RSTRING_LEN(str));
retv = rb_str_new2(buf);
xfree(buf);

View File

@ -0,0 +1,22 @@
diff --git a/test/tc_Stringprep.rb b/test/tc_Stringprep.rb
index c7f15cb..bcdd401 100644
--- a/test/tc_Stringprep.rb
+++ b/test/tc_Stringprep.rb
@@ -60,7 +60,7 @@ class Test_Stringprep < Test::Unit::TestCase
def test_with_profile_STRINGPREP
TESTCASES_STRINGPREP.each do |key, val|
rc = Stringprep.with_profile(val[1], val[0])
- assert_equal(val[2], rc, "TestCase #{key} failed")
+ assert_equal(val[2].force_encoding('ASCII-8BIT'), rc, "TestCase #{key} failed")
end
end
@@ -75,7 +75,7 @@ class Test_Stringprep < Test::Unit::TestCase
def test_nfkc_normalize_NFKC
TESTCASES_NFKC.each do |key, val|
rc = Stringprep.nfkc_normalize(val[0])
- assert_equal(val[1], rc, "TestCase #{key} failed")
+ assert_equal(val[1].force_encoding('ASCII-8BIT'), rc, "TestCase #{key} failed")
end
end
end

64
rubygem-idn.spec Normal file
View File

@ -0,0 +1,64 @@
%global gem_name idn
Name: rubygem-%{gem_name}
Version: 0.0.2
Release: 1
Summary: Ruby Bindings for the GNU LibIDN library
License: ASL 2.0 and LGPLv2+
URL: https://rubygems.org/gems/idn
Source0: https://rubygems.org/gems/%{gem_name}-%{version}.gem
Patch0: rubygem-idn-0.0.2-Fix-for-ruby-1.9.x.patch
Patch1: rubygem-idn-0.0.2-ruby2-encoding-in-tests-fix.patch
BuildRequires: ruby(release) rubygems-devel ruby-devel gcc libidn-devel rubygem(test-unit)
%description
Ruby Bindings for the GNU LibIDN library, an implementation of the Stringprep,
Punycode and IDNA specifications defined by the IETF Internationalized Domain
Names (IDN) working group.
%package doc
Summary: Documentation for %{name}
Requires: %{name} = %{version}-%{release}
BuildArch: noarch
%description doc
Documentation for %{name}.
%prep
%setup -q -n %{gem_name}-%{version}
%patch0 -p0
%patch1 -p1
%build
gem build ../%{gem_name}-%{version}.gemspec
%gem_install
%install
mkdir -p %{buildroot}%{gem_dir}
cp -a .%{gem_dir}/* \
%{buildroot}%{gem_dir}/
mkdir -p %{buildroot}%{gem_extdir_mri}
cp -a .%{gem_extdir_mri}/{gem.build_complete,*.so} %{buildroot}%{gem_extdir_mri}/
rm -rf %{buildroot}%{gem_instdir}/ext/
%check
pushd .%{gem_instdir}
ruby -I$(dirs +1)%{gem_extdir_mri} -e 'Dir.glob "./test/tc_*.rb", &method(:require)'
popd
%files
%dir %{gem_instdir}
%{gem_extdir_mri}
%license %{gem_instdir}/LICENSE
%exclude %{gem_libdir}
%exclude %{gem_cache}
%{gem_spec}
%files doc
%doc %{gem_docdir}
%doc %{gem_instdir}/CHANGES
%doc %{gem_instdir}/NOTICE
%doc %{gem_instdir}/README
%{gem_instdir}/Rakefile
%{gem_instdir}/test
%changelog
* Sat Jul 25 2020 wutao <wutao61@huawei.com> - 0.0.2-1
- package init

4
rubygem-idn.yaml Normal file
View File

@ -0,0 +1,4 @@
version_control: NA
src_repo: NA
tag_prefix: NA
seperator: NA