@@ -621,15 +621,17 @@ public string GetMatchingIfExists(string key, params object[] args)
621621 /// </summary>
622622 private static void LoadEntries ( Dictionary < string , string > entryCache , Dictionary < string , KeyValuePair < Regex , string > > regexCache , Dictionary < string , string > wildcardCache , JToken json , string domain = GlobalConstants . DefaultDomain )
623623 {
624- LoadEntries ( entryCache , regexCache , wildcardCache , json , new StringBuilder ( 256 ) , domain ) ;
624+ var key = new StringBuilder ( domain , 256 )
625+ . Append ( AssetLocation . LocationSeparator ) ;
626+ LoadEntries ( entryCache , regexCache , wildcardCache , json , key , domain , isFirstPart : true ) ;
625627 }
626628
627- private static void LoadEntries ( Dictionary < string , string > entryCache , Dictionary < string , KeyValuePair < Regex , string > > regexCache , Dictionary < string , string > wildcardCache , JToken json , StringBuilder key , string domain )
629+ private static void LoadEntries ( Dictionary < string , string > entryCache , Dictionary < string , KeyValuePair < Regex , string > > regexCache , Dictionary < string , string > wildcardCache , JToken json , StringBuilder key , string domain , bool isFirstPart )
628630 {
629631 switch ( json )
630632 {
631633 case JObject jsonObject :
632- if ( key . Length > 0 )
634+ if ( ! isFirstPart )
633635 {
634636 key . Append ( '-' ) ;
635637 }
@@ -639,20 +641,20 @@ private static void LoadEntries(Dictionary<string, string> entryCache, Dictionar
639641 {
640642 key . Length = prefixLength ;
641643 key . Append ( property . Name ) ;
642- LoadEntries ( entryCache , regexCache , wildcardCache , property . Value , key , domain ) ;
644+ LoadEntries ( entryCache , regexCache , wildcardCache , property . Value , key , domain , isFirstPart : false ) ;
643645 }
644646 break ;
645- case JValue jsonValue when jsonValue . Type == JTokenType . String && key . Length > 0 :
646- LoadEntry ( entryCache , regexCache , wildcardCache , key . ToString ( ) , jsonValue . ToString ( ) , domain ) ;
647+ case JValue jsonValue when jsonValue . Type == JTokenType . String && ! isFirstPart :
648+ LoadEntry ( entryCache , regexCache , wildcardCache , key , jsonValue . ToString ( ) , domain ) ;
647649 break ;
648650 default :
649651 throw new InvalidOperationException ( $ "Unexpected token: { json . Type } ") ;
650652 }
651653 }
652654
653- private static void LoadEntry ( Dictionary < string , string > entryCache , Dictionary < string , KeyValuePair < Regex , string > > regexCache , Dictionary < string , string > wildcardCache , string key , string value , string domain )
655+ private static void LoadEntry ( Dictionary < string , string > entryCache , Dictionary < string , KeyValuePair < Regex , string > > regexCache , Dictionary < string , string > wildcardCache , StringBuilder keyBuilder , string value , string domain )
654656 {
655- key = KeyWithDomain ( key , domain ) ;
657+ var key = EnsureSingleDomainPrefix ( keyBuilder , domain ) ;
656658 switch ( key . CountChars ( '*' ) )
657659 {
658660 case 0 :
@@ -671,6 +673,19 @@ private static void LoadEntry(Dictionary<string, string> entryCache, Dictionary<
671673 }
672674 }
673675
676+ private static string EnsureSingleDomainPrefix ( StringBuilder keyBuilder , string domain = GlobalConstants . DefaultDomain )
677+ {
678+ var key = keyBuilder . ToString ( ) ;
679+ var defaultDomainEndIndex = domain . Length + 1 ;
680+ if ( key . IndexOf ( AssetLocation . LocationSeparator , defaultDomainEndIndex ) >= 0 )
681+ {
682+ // Key contains a custom prefix, drop the default prefix
683+ return key . Substring ( defaultDomainEndIndex ) ;
684+ }
685+
686+ return key ;
687+ }
688+
674689 private static string KeyWithDomain ( string key , string domain = GlobalConstants . DefaultDomain )
675690 {
676691 if ( key . Contains ( AssetLocation . LocationSeparator ) ) return key ;
0 commit comments