@@ -112,6 +112,9 @@ window.assignManager = {
112
112
this . setExempted ( pageUrlorUrlKey , tabId ) ;
113
113
} ) ;
114
114
}
115
+ if ( data . wildcardHostname ) {
116
+ await this . removeDuplicateWildcardHostname ( data . wildcardHostname , siteStoreKey ) ;
117
+ }
115
118
await this . removeWildcardLookup ( siteStoreKey ) ;
116
119
// eslint-disable-next-line require-atomic-updates
117
120
data . identityMacAddonUUID =
@@ -157,6 +160,24 @@ window.assignManager = {
157
160
}
158
161
} ,
159
162
163
+ // Must not set the same wildcardHostname property on multiple sites.
164
+ // E.g. 'google.com' on both 'www.google.com' and 'mail.google.com'.
165
+ //
166
+ // Necessary because the stored wildcardLookup map is 1-to-1, i.e. either
167
+ // 'google.com' => 'www.google.com', or
168
+ // 'google.com' => 'mail.google.com', but not both!
169
+ async removeDuplicateWildcardHostname ( wildcardHostname , expectedSiteStoreKey ) {
170
+ const wildcardStoreKey = this . getWildcardStoreKey ( wildcardHostname ) ;
171
+ const siteStoreKey = await this . getByUrlKey ( wildcardStoreKey ) ;
172
+ if ( siteStoreKey && siteStoreKey !== expectedSiteStoreKey ) {
173
+ const siteSettings = await this . getByUrlKey ( siteStoreKey ) ;
174
+ if ( siteSettings && siteSettings . wildcardHostname === wildcardHostname ) {
175
+ delete siteSettings . wildcardHostname ;
176
+ await this . set ( siteStoreKey , siteSettings ) ; // Will cause wildcard mapping to be cleared
177
+ }
178
+ }
179
+ } ,
180
+
160
181
async deleteContainer ( userContextId ) {
161
182
const sitesByContainer = await this . getAssignedSites ( userContextId ) ;
162
183
this . area . remove ( Object . keys ( sitesByContainer ) ) ;
0 commit comments