Skip to content

Commit 2ac2524

Browse files
committed
Update default tokenPattern to be more reasonable.
1 parent f1f8e1a commit 2ac2524

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

samples/SampleWebApp/Web.config

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@
3333
<add name="KV4" vaultName="${ConfigBuilderTestKeyVaultName}" mode="Greedy" version="0de51928e49144ce86eb1de9056ac937" type="Microsoft.Configuration.ConfigurationBuilders.AzureKeyVaultConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.Azure, Version=2.0.0.0, Culture=neutral" />
3434

3535
<add name="AS_Sub_Test" optional="${Boolean}" type="Microsoft.Configuration.ConfigurationBuilders.EnvironmentConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.Environment, Version=2.0.0.0, Culture=neutral" />
36-
</builders>
36+
<add name="AS_Sub_Test2" optional="${app~Settings_Colon-and$friends@super+duper,awesome#cool:Test.}" type="Microsoft.Configuration.ConfigurationBuilders.EnvironmentConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.Environment, Version=2.0.0.0, Culture=neutral" />
37+
</builders>
3738
</configBuilders>
3839

3940
<appSettings configBuilders="Environment,Secrets,Json,KeyPerFile">
41+
<add key="app~Settings_Colon-and$friends@super+duper,awesome#cool:Test." value="true" />
4042
<add key="WINDIR" value="Will be replaced by 'Environment' in Strict and Greedy modes." />
4143
<add key="SYSTEMDRIVE" value="Will initally be replaced by 'Environment' in Strict and Greedy modes... but then superceded by 'Secrets' in the same modes." />
4244
<add key="Value_Replaced_By_Environment_In_Expand_Mode" value="${WINDIR}" />
@@ -62,7 +64,7 @@
6264
<!-- key="Secret3" value="Will be added by KV3:Latest3. IFF already added, will be "updated" by KV1 to Latest3. KV2 and KV4 don't have versions matching this secret." -->
6365
</appSettings>
6466

65-
<connectionStrings configBuilders="Json">
67+
<connectionStrings configBuilders="Json,AS_Sub_Test2">
6668
<add name="jsonConnectionString1" connectionString="Will be replaced by 'Json' in 'Flat' AND 'Sectional' jsonModes, but with different values." />
6769
<add name="connectionStrings:jsonConnectionString1" connectionString="Will only be replaced by 'Json' in 'Flat' jsonMode." />
6870
<add name="jsonConnectionString2" connectionString="Will only be replaced by 'Json' in 'Sectional' jsonMode." />

src/Base/KeyValueConfigBuilder.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,30 +37,35 @@ public abstract class KeyValueConfigBuilder : ConfigurationBuilder
3737
/// Gets or sets the substitution pattern to be used by the KeyValueConfigBuilder.
3838
/// </summary>
3939
public KeyValueMode Mode { get; private set; } = KeyValueMode.Strict;
40+
4041
/// <summary>
4142
/// Gets or sets a prefix string that must be matched by keys to be considered for value substitution.
4243
/// </summary>
4344
public string KeyPrefix { get { EnsureInitialized(); return _keyPrefix; } }
4445
private string _keyPrefix = "";
46+
4547
private bool StripPrefix { get { EnsureInitialized(); return _stripPrefix; } }
4648
private bool _stripPrefix = false; // Prefix-stripping is all handled in this base class; this is private so it doesn't confuse sub-classes.
4749
/// <summary>
4850
/// Specifies whether the config builder should cause errors if the backing source cannot be found.
4951
/// </summary>
5052
public bool Optional { get { EnsureInitialized(); return _optional; } protected set { _optional = value; } }
5153
private bool _optional = true;
54+
5255
/// <summary>
5356
/// Gets or sets a regular expression used for matching tokens in raw xml during Greedy substitution.
5457
/// </summary>
5558
public string TokenPattern { get { EnsureInitialized(); return _tokenPattern; } protected set { _tokenPattern = value; } }
56-
private string _tokenPattern = @"\$\{(\w+)\}";
59+
//private string _tokenPattern = @"\$\{(\w+)\}";
60+
private string _tokenPattern = @"\$\{(\w[\w-_$@#+,.:~]*)\}"; // Updated to be more reasonable for V2
5761

5862
/// <summary>
5963
/// Looks up a single 'value' for the given 'key.'
6064
/// </summary>
6165
/// <param name="key">The 'key' to look up in the config source. (Prefix handling is not needed here.)</param>
6266
/// <returns>The value corresponding to the given 'key' or null if no value is found.</returns>
6367
public abstract string GetValue(string key);
68+
6469
/// <summary>
6570
/// Retrieves all known key/value pairs for the configuration source where the key begins with with <paramref name="prefix"/>.
6671
/// </summary>
@@ -74,6 +79,7 @@ public abstract class KeyValueConfigBuilder : ConfigurationBuilder
7479
/// <param name="key">The string to be validated. May be partial.</param>
7580
/// <returns>True if the string is valid. False if the string is not a valid key.</returns>
7681
public virtual bool ValidateKey(string key) { return true; }
82+
7783
/// <summary>
7884
/// Transforms the raw key to a new string just before updating items in Strict and Greedy modes.
7985
/// </summary>

0 commit comments

Comments
 (0)