Skip to content

Commit

Permalink
Merge pull request PowerShell#2375 from mirichmo/mirichmo/validating-…
Browse files Browse the repository at this point in the history
…properties-reads

Validating JSON Properties File Reads Prior to Processing
  • Loading branch information
vors committed Sep 28, 2016
2 parents 18f732f + adf6250 commit f45c6f2
Show file tree
Hide file tree
Showing 3 changed files with 996 additions and 969 deletions.
13 changes: 9 additions & 4 deletions src/System.Management.Automation/engine/PropertyAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,16 @@ private T ReadValueFromFile<T>(string fileName, string key)
using (StreamReader streamRdr = new StreamReader(fs))
using (JsonTextReader jsonReader = new JsonTextReader(streamRdr))
{
JObject jsonObject = (JObject) JToken.ReadFrom(jsonReader);
JToken value = jsonObject.GetValue(key);
if (null != value)
// Safely determines whether there is content to read from the file
bool isReadSuccess = jsonReader.Read();
if (isReadSuccess)
{
return value.ToObject<T>();
JObject jsonObject = (JObject) JToken.ReadFrom(jsonReader);
JToken value = jsonObject.GetValue(key);
if (null != value)
{
return value.ToObject<T>();
}
}
}
}
Expand Down
Loading

0 comments on commit f45c6f2

Please sign in to comment.