Giter Site home page Giter Site logo

psyaml's People

Contributors

brian-k-marsh avatar hsitin avatar pezhore avatar phil-factor avatar secretgeek avatar vyrp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

psyaml's Issues

Long hashtable values incorrectly wraps

I have the following generic logic:

import-module psyaml

## local variables
$my_arr = @()
$my_hash = @{}
$blahs = @('one', 'two', 'three')
$something = @(@{Name = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'})

## generate output
foreach ($someValue in $something) {
    foreach ($blah in $blahs) {
        $my_hash += @{$blah = $someValue.Name}
    }
}
$my_arr += @{'zzzz' = $my_hash}

## convert to yaml
$my_arr | ConvertTo-YAML

I end up getting output that looks like:

---

  zzzz: 
    one: >
    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

 
    three: >
    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

 
    two: >
    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Install-Module doest not work

PackageManagement\Install-Package : No match was found for the specified search criteria and module name 'PSYaml'. Try Get-PSRepository to see all available registered module repositories.

Getting this when trying to install the module

ConvertTo-Yaml Invalid cmdlet names

Looks like a find/replace gone awry in ConvertTo-Yaml.ps1. Multiple references to Select-Object-Object and Where-Object-Object cmdlets which of course do not exist.

Converts to Datetime (Unwanted)

ConvertFrom-Yaml is converting strings to datetime.

I understand that '12/31/1999' looks like a date format, but i am passing it in as a string because i want the value to actually be '12/31/1999'

# Test YAML
$y = @"
test:
  tag: 12/31/1999
@"

# Converts to PS object
$PSObj = $y | ConvertToYaml

# Outputs the results
C:\> $PSObj['test']

Name                  Value
----                      -----
tag                      12/31/1999 12:00:00 AM

# Shows the type
C:\> $PSObj['test'].tag.gettype()

IsPublic IsSerial Name
-------- -------- ----
True     True     DateTime

Invalid path to YamlDotNet assembly in Initialize-PsYAML_Module

Hello!

I'm using this module for the first time, following the recommend initial load code on your website.

I find that when the module initializes, it's trying to find the YamlDotNet assembly in the wrong path.

VERBOSE: Performing the operation "Set Alias" on target "Name: nuget Value:
C:\Users\luke.ryan\Documents\WindowsPowerShell\Modules\PSYaml\nuget.exe".
Add-Type : Cannot bind parameter 'Path' to the target. Exception setting "Path": "Cannot find path
'C:\Users\luke.ryan\Documents\WindowsPowerShell\Modules\PSYaml\YAMLDotNet\YamlDotNet.4.2.1\lib\dotnet\yamldotnet.dll'
because it does not exist."
At C:\Users\luke.ryan\Documents\WindowsPowerShell\Modules\psyaml\PSYaml.psm1:44 char:20

  • ... -Type -Path "$YAMLDotNetLocation\YAMLDotNet$CurrentRelease\lib\dotne ...
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : WriteError: (:) [Add-Type], ParameterBindingException
    • FullyQualifiedErrorId : ParameterBindingFailed,Microsoft.PowerShell.Commands.AddTypeCommand

Single-element arrays are not preserved

convertfrom-yaml does not preserve single-element arrays.

Example:

# Create a hash with two key-value pairs.  Both values are arrays, but one of them 
# has just a single element
$j = [ordered]@{
  apac = @('Australia')
  emea = @('Italy', 'Finland')
}

#Confirm that both values are arrays
PS C:\> $j.apac.gettype().name
Object[]
PS C:\> $j.emea.gettype().name
Object[]

# Convert to yaml.  Good so far, we still have two arrays/sequences.
PS C:\> $j | convertto-yaml
---

  apac:
  - 'Australia'
  emea:
  - 'Italy'
  - 'Finland'

# Convert back to a PowerShell object and we lose one of the arrays.
# Now we have one array and one scalar.  We should have two arrays.
PS C:\> $j = $j | convertto-yaml | convertfrom-yaml
PS C:\> $j.apac.gettype().name
String
PS C:\> $j.emea.gettype().name
Object[]

Strings containing numbers or dates are converted to numbers and dates

Summary

When converting a YAML document containing strings that could represent numbers or dates, ConvertFrom-YAML will always convert them to numbers or dates.

Environment

  • Windows 10 Pro x64
  • Windows Powershell 5.1.15063.786
  • PSYaml 1.0.2, installed via Install-Package

Steps to reproduce

  1. Create a valid YAML document
  2. Add a string value which contains a number or a date
  3. Convert the document via ConvertFrom-Yaml

Actual result

String values that look like numbers are dates are converted to number or date objects:

> $fromYaml = ConvertFrom-Yaml -YamlString @"
one: thing
two: "2"
three: "2014-04-01"
"@

> $fromYaml.two; $fromYaml.two.GetType().Name
2
Int32

> $fromYaml.three; $fromYaml.three.GetType().Name
Tuesday, April 1, 2014 12:00:00 AM
DateTime

Expected result

I expected that, just like with the native ConvertFrom-Json cmdlet, string values are preserved as strings, rather than converted to numbers or dates, as long as the values are wrapped in double quotes.

Here is similar output for the ConvertFrom-Json cmdlet, showing that strings are preserved:

> $fromJson = ConvertFrom-Json -InputObject '{"one": "thing", "two": "2", "three": "2014-04-01"}'

> $fromJson.two; $fromJson.two.GetType().Name
2
String

> $fromJson.three; $fromJson.three.GetType().Name
2014-04-01
String

For what it's worth, other YAML converters had my expected output, where strings are preserved. For instance, here is the PyYAML module for Python converting a YAML string into a Python dict:

>>> import yaml

>>> from_yaml = yaml.load("""
... one: thing
... two: "2"
... three: "2014-04-01"
... """)

>>> from_yaml['two']; type(from_yaml['two'])
'2'
<class 'str'>

>>> from_yaml['three']; type(from_yaml['three'])
'2014-04-01'
<class 'str'>

Workaround

Happily, there is a workaround for anyone else who might run into this. PSYaml supports YAML tags, as documented in the readme. If you have control over the input YAML document, you can prepend the !!str tag to the value that should remain a string, like so:

> $fromTaggedYaml = ConvertFrom-Yaml -YamlString @"
one: thing
two: !!str "2"
three: !!str "2014-04-01"
"@

> $fromTaggedYaml.two; $fromTaggedYaml.two.GetType().Name
2
String

> $fromTaggedYaml.three; $fromTaggedYaml.three.GetType().Name
2014-04-01
String

Set-StrictMode in tests

Hi, apologise for the extra noise but I came across the usage of Set-StrictMode in your tests like https://github.com/Phil-Factor/PSYaml/blob/master/Tests/PSYaml.ConvertFrom.Tests.ps1#L64. Your description indicates that the -Version refers to the PowerShell version it is testing against but it's my understanding that StrictMode has 1.0, 2.0, and latest which are specific rule sets and not PS version compatibilities. Am I misunderstanding the use of Set-StrictMode here or are those extra tests not doing what they should be doing?

Create a release?

Would you be able to create a release? I can get the module more easily that way.

invoke-webrequest -uri http://github.com/phil-factor/psyaml/0.1.2.zip -outfile psyaml.zip 

Does not properly convert nested lists

Given a file with this content:

- test1
-   - test2
    - test3

the expected output from piping this file's content to ConvertFrom-Yaml would be a list with 'test1' and a nested list with 'test2' and 'test3'. This should be the proper formatting for nested lists in YAML and converting this YAML file in Python, with the PyYAML module, exhibits this behavior.

However, the ConvertFrom-Yaml cmdlet returns a list with 'test1', 'test2', and 'test3'.

Bug: $false as Boolean value creates an empty output

Hi there:

Found a small issue in CovertTo-Yaml.ps1:

        # if it is null return null
        If ( !($inputObject) )

Should be:

        # if it is null return null
        If ( $inputObject -eq $null )

Reason:
If the object itself is "$false", it will return an empty yaml value

How to reproduce:

$test = [PSCustomObject]@{TestValue = $false }
ConvertTo-Yaml $test

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.