Jira (FACT-1793) Facter incorrectly outputs backslash characters in default output

3 views
Skip to first unread message

Glenn Sarti (JIRA)

unread,
Nov 2, 2017, 4:03:06 PM11/2/17
to puppe...@googlegroups.com
Glenn Sarti updated an issue
 
Facter / Bug FACT-1793
Facter incorrectly outputs backslash characters in default output
Change By: Glenn Sarti
Summary: Facter incorrectly  parses  outputs  backslash characters in default output
Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.0.2#70111-sha1:88534db)
Atlassian logo

Glenn Sarti (JIRA)

unread,
Nov 2, 2017, 4:04:03 PM11/2/17
to puppe...@googlegroups.com
Glenn Sarti updated an issue
When using a simple custom fact of 
{code}
Facter.add(:sqlserver_instances) do
  setcode do
   {"sqlserver_instances" => {
      "SQL_2012" => {},
      "SQL_2014"=> {},
      "SQL_2016"=> {
        "MSSQLSERVER" => {
          "name" => "MSSQLSERVER",
          "version_friendly" => "SQL_2016",
          "version" => "13.1.4001.0",
          "reg_root" => "Software\\Microsoft\\Microsoft SQL Server\\MSSQL13.MSSQLSERVER",
          "features" => [
            "SQLEngine"
          ]
        }
      }
    }}
  end
end
{code}

Running facter outputs text which does not seem to have the correct backslash escaping
{code}

Change FACTERLIB

PS C:\source\sqlserver> facter sqlserver_instances                                                      
{                                                                                                       
  sqlserver_instances => {                                                                              
    SQL_2012 => {},                                                                                     
    SQL_2014 => {},                                                                                     
    SQL_2016 => {                                                                                       
      MSSQLSERVER => {                                                                                  
        name => "MSSQLSERVER",                                                                          
        version_friendly => "SQL_2016",                                                                 
        version => "13.1.4001.0",                                                                       
        reg_root => "Software\Microsoft\Microsoft SQL Server\MSSQL13.MSSQLSERVER",
                      
                 <----- These backslashes should be escaped.     
        features => [                                                                                   
          "SQLEngine"                                                                                   
        ]                                                                                               
      }                                                                                                 
    }                                                                                                   
  }                                                                                                     
}                                                                                                       
{code}

{code}
Using Puppet Facts

   "sqlserver_instances": {
      "sqlserver_instances": {
        "SQL_2012": {

        },
        "SQL_2014": {

        },
        "SQL_2016": {
          "MSSQLSERVER": {
            "name": "MSSQLSERVER",
            "version_friendly": "SQL_2016",
            "version": "13.1.4001.0",
            "reg_root": "Software\\Microsoft\\Microsoft SQL Server\\MSSQL13.MSSQLSERVER",
            "features": [
              "SQLEngine"
            ]
          }
        }
      }
    },
{code}

{code}
Outputing in YAML format

sqlserver_instances:
  sqlserver_instances:
    SQL_2012:
      {}
    SQL_2014:
      {}
    SQL_2016:
      MSSQLSERVER:
        name: MSSQLSERVER
        version_friendly: SQL_2016
        version: 13.1.4001.0
        reg_root: Software\Microsoft\Microsoft SQL Server\MSSQL13.MSSQLSERVER
        features:
          - SQLEngine
PS C:\source\sqlserver>
{code}

It is expected that the hash output from facter is ruby-ish so the backslashes should be escaped correctly

Branan Riley (JIRA)

unread,
Jan 2, 2018, 1:40:03 PM1/2/18
to puppe...@googlegroups.com
Branan Riley commented on Bug FACT-1793
 
Re: Facter incorrectly outputs backslash characters in default output

Do YAML or JSON require escaping of backslashes? If so, this is a bug in the libraries we use to output those formats (which we can and should totally work around if needed).

If those formats do not require escaping, then I'd say this is expected behavior - Ruby eats the escape, so the string that is output matches "what you put in"

Glenn Sarti (JIRA)

unread,
Jan 2, 2018, 7:29:02 PM1/2/18
to puppe...@googlegroups.com
Glenn Sarti commented on Bug FACT-1793

However the facter output is supposed to be rubyish AFAIK.

Glenn Sarti (JIRA)

unread,
Jan 2, 2018, 7:29:03 PM1/2/18
to puppe...@googlegroups.com
Glenn Sarti commented on Bug FACT-1793

JSON definitely does. backslash is the escape character.

YAML seems to be

Looks like single quoted strings no, double quoted strings yes.

http://yaml.org/spec/history/2001-08-01.html
"YAML's quoted strings are similar to C's. In YAML, text scalars can be surrounded by quotes enabling escape sequences such as \n to represent a new line, \t to represent a tab, and
to represent the backslash. Unlike C, since line break is folded into a space, a trailing \ is used as a continuation marker, allowing content to be broken into multiple lines without introducing unwanted whitespace. Further, YAML treats an empty line (two consecutive line breaks) as being equivalent to \n. Lastly, 8-bit (ISO 8859-1) characters can be specified using "\x3B" style escapes, 16-bit (Unicode) characters can be specified using "\u003B" style escapes, and 32-bit (ISO/IEC 10646) characters can be specified using "\U0000003B" style escapes."

Branan Riley (JIRA)

unread,
Jan 9, 2018, 5:48:03 PM1/9/18
to puppe...@googlegroups.com
Branan Riley commented on Bug FACT-1793

Yeah. The "rubyish" output is probably worth us manually adding escaping to. I totally thought that was the JSON output when I went through this the first time, sorry!

Branan Riley (JIRA)

unread,
Jan 9, 2018, 5:49:02 PM1/9/18
to puppe...@googlegroups.com

Glenn Sarti (JIRA)

unread,
Jan 9, 2018, 8:25:02 PM1/9/18
to puppe...@googlegroups.com

Branan Riley (JIRA)

unread,
Mar 21, 2018, 7:31:03 PM3/21/18
to puppe...@googlegroups.com
Branan Riley updated an issue
Change By: Branan Riley
Labels: cli triaged
This message was sent by Atlassian JIRA (v7.7.1#77002-sha1:e75ca93)
Atlassian logo

Josh Cooper (Jira)

unread,
Jan 14, 2022, 12:12:01 AM1/14/22
to puppe...@googlegroups.com
This message was sent by Atlassian Jira (v8.20.2#820002-sha1:829506d)
Atlassian logo
Reply all
Reply to author
Forward
0 new messages