Title: [206949] trunk
Revision
206949
Author
[email protected]
Date
2016-10-07 20:31:15 -0700 (Fri, 07 Oct 2016)

Log Message

window.navigator.language incorrectly returns all lowercase string
https://bugs.webkit.org/show_bug.cgi?id=163096

Reviewed by Darin Adler.

Source/WebCore:

Update navigator.language so that it no longer returns an all lowercase
string (e.g. 'en-us' -> 'en-US'). This matches the behavior of other
browsers and the specification which indicate we should return a
BCP 47 language tag:
- https://html.spec.whatwg.org/#dom-navigator-language
- https://tools.ietf.org/html/bcp47

The other call sites relying on userPreferredLanguages() use case
insensitive comparison so they will not break.

No new tests, updated existing test.

* platform/Language.h:

Source/WTF:

Update platformUserPreferredLanguages() so that it no longer lowercases
the string it returns. On Mac, we rely on CFLocale which returns
BCP-47 language tags as per:
- https://developer.apple.com/reference/corefoundation/1666963-cflocale?language=objc

* wtf/PlatformUserPreferredLanguagesMac.mm:
(WTF::httpStyleLanguageCode):
* wtf/PlatformUserPreferredLanguagesUnix.cpp:
(WTF::platformLanguage):

LayoutTests:

Update existing test so that it does not lowercase navigator.language
before checking it. This way, we can make sure it returns en-US and
not en-us.

* js/dom/navigator-language-expected.txt:
* js/dom/navigator-language.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (206948 => 206949)


--- trunk/LayoutTests/ChangeLog	2016-10-08 03:20:53 UTC (rev 206948)
+++ trunk/LayoutTests/ChangeLog	2016-10-08 03:31:15 UTC (rev 206949)
@@ -1,3 +1,17 @@
+2016-10-07  Chris Dumez  <[email protected]>
+
+        window.navigator.language incorrectly returns all lowercase string
+        https://bugs.webkit.org/show_bug.cgi?id=163096
+
+        Reviewed by Darin Adler.
+
+        Update existing test so that it does not lowercase navigator.language
+        before checking it. This way, we can make sure it returns en-US and
+        not en-us.
+
+        * js/dom/navigator-language-expected.txt:
+        * js/dom/navigator-language.html:
+
 2016-10-07  Yusuke Suzuki  <[email protected]>
 
         REGRESSION (r206853?): LayoutTest js/regress-141098.html failing

Modified: trunk/LayoutTests/js/dom/navigator-language-expected.txt (206948 => 206949)


--- trunk/LayoutTests/js/dom/navigator-language-expected.txt	2016-10-08 03:20:53 UTC (rev 206948)
+++ trunk/LayoutTests/js/dom/navigator-language-expected.txt	2016-10-08 03:31:15 UTC (rev 206949)
@@ -2,7 +2,7 @@
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 
 
-PASS language is 'en-us'
+PASS language is 'en-US'
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/js/dom/navigator-language.html (206948 => 206949)


--- trunk/LayoutTests/js/dom/navigator-language.html	2016-10-08 03:20:53 UTC (rev 206948)
+++ trunk/LayoutTests/js/dom/navigator-language.html	2016-10-08 03:31:15 UTC (rev 206949)
@@ -14,11 +14,11 @@
     testRunner.setPOSIXLocale("en_US.iso88591");
 }
 
-var language = navigator.language.toLowerCase();
+var language = navigator.language;
 if (language.length == 2)
     shouldBe("language", "'en'");
 else
-    shouldBe("language", "'en-us'");
+    shouldBe("language", "'en-US'");
 </script>
 <script src=""
 </body>

Modified: trunk/Source/WTF/ChangeLog (206948 => 206949)


--- trunk/Source/WTF/ChangeLog	2016-10-08 03:20:53 UTC (rev 206948)
+++ trunk/Source/WTF/ChangeLog	2016-10-08 03:31:15 UTC (rev 206949)
@@ -1,3 +1,20 @@
+2016-10-07  Chris Dumez  <[email protected]>
+
+        window.navigator.language incorrectly returns all lowercase string
+        https://bugs.webkit.org/show_bug.cgi?id=163096
+
+        Reviewed by Darin Adler.
+
+        Update platformUserPreferredLanguages() so that it no longer lowercases
+        the string it returns. On Mac, we rely on CFLocale which returns
+        BCP-47 language tags as per:
+        - https://developer.apple.com/reference/corefoundation/1666963-cflocale?language=objc
+
+        * wtf/PlatformUserPreferredLanguagesMac.mm:
+        (WTF::httpStyleLanguageCode):
+        * wtf/PlatformUserPreferredLanguagesUnix.cpp:
+        (WTF::platformLanguage):
+
 2016-10-06  Brent Fulgham  <[email protected]>
 
         [Win][Direct2D] Add Direct2D CMake rules

Modified: trunk/Source/WTF/wtf/PlatformUserPreferredLanguagesMac.mm (206948 => 206949)


--- trunk/Source/WTF/wtf/PlatformUserPreferredLanguagesMac.mm	2016-10-08 03:20:53 UTC (rev 206948)
+++ trunk/Source/WTF/wtf/PlatformUserPreferredLanguagesMac.mm	2016-10-08 03:31:15 UTC (rev 206949)
@@ -80,10 +80,10 @@
 static String httpStyleLanguageCode(NSString *language)
 {
     SInt32 languageCode;
-    SInt32 regionCode; 
-    SInt32 scriptCode; 
+    SInt32 regionCode;
+    SInt32 scriptCode;
     CFStringEncoding stringEncoding;
-    
+
     // FIXME: This transformation is very wrong:
     // 1. There is no reason why CFBundle localization names would be at all related to language names as used on the Web.
     // 2. Script Manager codes cannot represent all languages that are now supported by the platform, so the conversion is lossy.
@@ -93,17 +93,14 @@
     if (preferredLanguageCode)
         language = (NSString *)preferredLanguageCode.get();
 
-    // Make the string lowercase.
-    NSString *lowercaseLanguageCode = [language lowercaseString];
-        
     // Turn a '_' into a '-' if it appears after a 2-letter language code
-    if ([lowercaseLanguageCode length] >= 3 && [lowercaseLanguageCode characterAtIndex:2] == '_') {
-        RetainPtr<NSMutableString> mutableLanguageCode = adoptNS([lowercaseLanguageCode mutableCopy]);
+    if ([language length] >= 3 && [language characterAtIndex:2] == '_') {
+        RetainPtr<NSMutableString> mutableLanguageCode = adoptNS([language mutableCopy]);
         [mutableLanguageCode.get() replaceCharactersInRange:NSMakeRange(2, 1) withString:@"-"];
         return mutableLanguageCode.get();
     }
 
-    return lowercaseLanguageCode;
+    return language;
 }
 
 Vector<String> platformUserPreferredLanguages()

Modified: trunk/Source/WTF/wtf/PlatformUserPreferredLanguagesUnix.cpp (206948 => 206949)


--- trunk/Source/WTF/wtf/PlatformUserPreferredLanguagesUnix.cpp	2016-10-08 03:20:53 UTC (rev 206948)
+++ trunk/Source/WTF/wtf/PlatformUserPreferredLanguagesUnix.cpp	2016-10-08 03:31:15 UTC (rev 206949)
@@ -36,9 +36,9 @@
 {
     String localeDefault(setlocale(LC_CTYPE, nullptr));
     if (localeDefault.isEmpty() || equalIgnoringASCIICase(localeDefault, "C") || equalIgnoringASCIICase(localeDefault, "POSIX"))
-        return ASCIILiteral("en-us");
+        return ASCIILiteral("en-US");
 
-    String normalizedDefault = localeDefault.convertToASCIILowercase();
+    String normalizedDefault = localeDefault;
     normalizedDefault.replace('_', '-');
     normalizedDefault.truncate(normalizedDefault.find('.'));
     return normalizedDefault;

Modified: trunk/Source/WebCore/ChangeLog (206948 => 206949)


--- trunk/Source/WebCore/ChangeLog	2016-10-08 03:20:53 UTC (rev 206948)
+++ trunk/Source/WebCore/ChangeLog	2016-10-08 03:31:15 UTC (rev 206949)
@@ -1,3 +1,24 @@
+2016-10-07  Chris Dumez  <[email protected]>
+
+        window.navigator.language incorrectly returns all lowercase string
+        https://bugs.webkit.org/show_bug.cgi?id=163096
+
+        Reviewed by Darin Adler.
+
+        Update navigator.language so that it no longer returns an all lowercase
+        string (e.g. 'en-us' -> 'en-US'). This matches the behavior of other
+        browsers and the specification which indicate we should return a
+        BCP 47 language tag:
+        - https://html.spec.whatwg.org/#dom-navigator-language
+        - https://tools.ietf.org/html/bcp47
+
+        The other call sites relying on userPreferredLanguages() use case
+        insensitive comparison so they will not break.
+
+        No new tests, updated existing test.
+
+        * platform/Language.h:
+
 2016-10-07  Wenson Hsieh  <[email protected]>
 
         Support onbeforeinput event handling for the new InputEvent spec

Modified: trunk/Source/WebCore/platform/Language.h (206948 => 206949)


--- trunk/Source/WebCore/platform/Language.h	2016-10-08 03:20:53 UTC (rev 206948)
+++ trunk/Source/WebCore/platform/Language.h	2016-10-08 03:31:15 UTC (rev 206949)
@@ -32,7 +32,7 @@
 namespace WebCore {
 
 WEBCORE_EXPORT String defaultLanguage(); // Thread-safe.
-WEBCORE_EXPORT Vector<String> userPreferredLanguages(); // Thread-safe.
+WEBCORE_EXPORT Vector<String> userPreferredLanguages(); // Thread-safe, returns BCP 47 language tags.
 Vector<String> userPreferredLanguagesOverride();
 WEBCORE_EXPORT void overrideUserPreferredLanguages(const Vector<String>&);
 size_t indexOfBestMatchingLanguageInList(const String& language, const Vector<String>& languageList, bool& exactMatch);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to