Skip to content

Commit fb4c8a3

Browse files
committed
lang() pseudo function value check (wildcard ranges are not checked, only tags)
1 parent 0ff3daa commit fb4c8a3

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

org/w3c/css/selectors/PseudoFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public static PseudoFunctionSelector newPseudoFunction(String name,
203203
"null pseudofunction", ac);
204204
}
205205
if (name.equals("lang")) {
206-
return new PseudoFunctionLang(name, value);
206+
return new PseudoFunctionLang(name, value, ac);
207207
}
208208
if (name.equals("not")) {
209209
return new PseudoFunctionNot(name, value);

org/w3c/css/selectors/pseudofunctions/PseudoFunctionLang.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,49 @@
55
package org.w3c.css.selectors.pseudofunctions;
66

77
import org.w3c.css.selectors.PseudoFunctionSelector;
8+
import org.w3c.css.util.ApplContext;
9+
import org.w3c.css.util.InvalidParamException;
10+
11+
import java.util.IllformedLocaleException;
12+
import java.util.Locale;
13+
import java.util.Locale.Builder;
814

915
/**
1016
* PseudoFunctionLang<br />
1117
* Created: Sep 2, 2005 4:24:48 PM<br />
1218
*/
1319
public class PseudoFunctionLang extends PseudoFunctionSelector {
1420

15-
public PseudoFunctionLang(String name, String lang) {
21+
public PseudoFunctionLang(String name, String lang, ApplContext ac)
22+
throws InvalidParamException {
1623
setName(name);
24+
parseLang(ac, lang, name);
1725
setParam(lang);
1826
}
1927

28+
/**
29+
* verify a language tag per BCP47
30+
*
31+
* @param ac the ApplContext
32+
* @param lang the language tag
33+
* @param caller the property/selector/context calling for verification
34+
* @throws InvalidParamException if invalid
35+
*/
36+
public static final void parseLang(ApplContext ac, String lang, String caller)
37+
throws InvalidParamException {
38+
try {
39+
String lang_tag = lang;
40+
if (lang.charAt(0) == '"' || lang.charAt(0) == '\'') {
41+
// trim the string
42+
lang_tag = lang.substring(1, lang.lastIndexOf(lang.charAt(0)));
43+
}
44+
// use Locale builder parsing to check BCP 47 values
45+
Builder builder = new Builder();
46+
builder.setLanguageTag(lang_tag);
47+
Locale l = builder.build();
48+
} catch (IllformedLocaleException ex) {
49+
throw new InvalidParamException("value", lang, caller, ac);
50+
}
51+
}
52+
2053
}

0 commit comments

Comments
 (0)