From f46134e87fa563a14610d032f15dc589187a560a Mon Sep 17 00:00:00 2001 From: evazion Date: Wed, 24 Aug 2022 14:47:00 -0500 Subject: [PATCH] Fix #5234: Weibo URLs get normalized incorrectly in some cases. --- app/logical/source/url/weibo.rb | 11 +++++++++-- test/unit/sources/weibo_test.rb | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/logical/source/url/weibo.rb b/app/logical/source/url/weibo.rb index efd541c62..88e81ded8 100644 --- a/app/logical/source/url/weibo.rb +++ b/app/logical/source/url/weibo.rb @@ -9,9 +9,9 @@ # http://blog.sina.com.cn/u/1299088063 class Source::URL::Weibo < Source::URL - RESERVED_USERNAMES = %w[u p profile status detail] + RESERVED_USERNAMES = %w[u n p profile status detail] - attr_reader :full_image_url, :artist_short_id, :artist_long_id, :username + attr_reader :full_image_url, :artist_short_id, :artist_long_id, :display_name, :username def self.match?(url) url.domain.in?(["weibo.com", "weibo.cn", "sinaimg.cn"]) @@ -74,6 +74,11 @@ class Source::URL::Weibo < Source::URL in _, /^\d+$/ => artist_short_id, *rest @artist_short_id = artist_short_id + # https://weibo.com/n/肆巳4 + # https://www.weibo.com/n/小小男爵不要坑 + in _, "n", display_name, *rest + @display_name = display_name + # https://www.weibo.com/endlessnsmt (short id: https://www.weibo.com/u/1879370780) # https://www.weibo.cn/endlessnsmt # https://www.weibo.com/lvxiuzi0/home @@ -94,6 +99,8 @@ class Source::URL::Weibo < Source::URL "https://www.weibo.com/u/#{artist_short_id}" elsif artist_long_id.present? "https://www.weibo.com/p/#{artist_long_id}" + elsif display_name.present? + "https://www.weibo.com/n/#{display_name}" elsif username.present? "https://www.weibo.com/#{username}" end diff --git a/test/unit/sources/weibo_test.rb b/test/unit/sources/weibo_test.rb index a249399bd..d033bd820 100644 --- a/test/unit/sources/weibo_test.rb +++ b/test/unit/sources/weibo_test.rb @@ -138,6 +138,7 @@ module Sources assert(Source::URL.profile_url?("https://www.weibo.com/5501756072")) assert(Source::URL.profile_url?("https://www.weibo.com/endlessnsmt")) assert(Source::URL.profile_url?("https://www.weibo.com/4ubergine/photos")) + assert(Source::URL.profile_url?("https://www.weibo.com/n/小小男爵不要坑")) refute(Source::URL.profile_url?("https://weibo.com/u/")) end