@@ -601,13 +601,18 @@ def extended_language_filter(self, lang_range: str, lang_tag: str) -> bool:
601601 ranges = lang_range .split ('-' )
602602 subtags = lang_tag .lower ().split ('-' )
603603 length = len (ranges )
604+ slength = len (subtags )
604605 rindex = 0
605606 sindex = 0
606607 r = ranges [rindex ]
607608 s = subtags [sindex ]
608609
610+ # Empty specified language should match unspecified language attributes
611+ if length == 1 and slength == 1 and not r and r == s :
612+ return True
613+
609614 # Primary tag needs to match
610- if r != '*' and r != s :
615+ if ( r != '*' and r != s ) or ( r == '*' and slength == 1 and not s ) :
611616 match = False
612617
613618 rindex += 1
@@ -1184,7 +1189,7 @@ def match_lang(self, el: bs4.Tag, langs: tuple[ct.SelectorLang, ...]) -> bool:
11841189 break
11851190
11861191 # Use cached meta language.
1187- if not found_lang and self .cached_meta_lang :
1192+ if found_lang is None and self .cached_meta_lang :
11881193 for cache in self .cached_meta_lang :
11891194 if root is cache [0 ]:
11901195 found_lang = cache [1 ]
@@ -1218,13 +1223,13 @@ def match_lang(self, el: bs4.Tag, langs: tuple[ct.SelectorLang, ...]) -> bool:
12181223 found_lang = content
12191224 self .cached_meta_lang .append ((cast (str , root ), cast (str , found_lang )))
12201225 break
1221- if found_lang :
1226+ if found_lang is not None :
12221227 break
1223- if not found_lang :
1228+ if found_lang is None :
12241229 self .cached_meta_lang .append ((cast (str , root ), '' ))
12251230
12261231 # If we determined a language, compare.
1227- if found_lang :
1232+ if found_lang is not None :
12281233 for patterns in langs :
12291234 match = False
12301235 for pattern in patterns :
0 commit comments