| 103 | * or from the global `ng.common.locale`. |
| 104 | */ |
| 105 | export function getLocaleData(normalizedLocale: string): any { |
| 106 | if (!(normalizedLocale in LOCALE_DATA)) { |
| 107 | const globalLocaleData = |
| 108 | global.ng && |
| 109 | global.ng.common && |
| 110 | global.ng.common.locales && |
| 111 | global.ng.common.locales[normalizedLocale]; |
| 112 | // Only cache global locale data when an entry is actually found, to avoid |
| 113 | // caching missing lookups. In SSR this cache is process-wide across requests, |
| 114 | // so caching `undefined` would retain attacker-controlled locale identifiers |
| 115 | // indefinitely. It would also make the `in` check above short-circuit on |
| 116 | // subsequent lookups and skip the global fallback. |
| 117 | if (globalLocaleData !== undefined) { |
| 118 | LOCALE_DATA[normalizedLocale] = globalLocaleData; |
| 119 | } |
| 120 | return globalLocaleData; |
| 121 | } |
| 122 | return LOCALE_DATA[normalizedLocale]; |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Helper function to remove all the locale data from `LOCALE_DATA`. |