diff --git a/lib/common/models/wp_user/existable.rb b/lib/common/models/wp_user/existable.rb
index 2006ce62..b4d2c530 100755
--- a/lib/common/models/wp_user/existable.rb
+++ b/lib/common/models/wp_user/existable.rb
@@ -39,7 +39,9 @@ class WpUser < WpItem
#
# @return [ String ] The login
def self.login_from_author_pattern(text)
- text[%r{/author/([^/\b]+)/?}i, 1]
+ return unless text =~ %r{/author/([^/\b]+)/?}i
+
+ Regexp.last_match[1].force_encoding('UTF-8')
end
# @param [ String ] body
@@ -52,6 +54,7 @@ class WpUser < WpItem
unless login
# No Permalinks
login = body[%r{
+
+
+
+
+一路疯下去
+
+
+
+
diff --git a/spec/shared_examples/wp_user/existable.rb b/spec/shared_examples/wp_user/existable.rb
index 1499fcd3..ab0e5058 100644
--- a/spec/shared_examples/wp_user/existable.rb
+++ b/spec/shared_examples/wp_user/existable.rb
@@ -2,7 +2,7 @@
shared_examples 'WpUser::Existable' do
let(:mod) { WpUser::Existable }
- let(:fixtures_dir) { MODELS_FIXTURES + '/wp_user/existable' }
+ let(:fixtures_dir) { File.join(MODELS_FIXTURES, 'wp_user', 'existable') }
describe '::login_from_author_pattern' do
after do
@@ -145,7 +145,7 @@ shared_examples 'WpUser::Existable' do
end
context 'with a 200' do
- let(:resp_opt) { { code: 200, body: File.new(fixtures_dir + '/admin.html').read } }
+ let(:resp_opt) { { code: 200, body: File.read(File.join(fixtures_dir, 'admin.html')) } }
it 'loads the correct values' do
@login = 'admin'
@@ -153,6 +153,15 @@ shared_examples 'WpUser::Existable' do
end
end
+ context 'when chinese chars' do
+ let(:resp_opt) { { code: 200, body: File.read(File.join(fixtures_dir, 'chinese_chars.html')) } }
+
+ it 'loads the correct values' do
+ @login = '一路疯下去'
+ @display_name = nil
+ end
+ end
+
context 'otherwise' do
it 'does not do anything' do
@resp_opt = { code: 404 }