Project

General

Profile

Actions

Bug #39564

open

json/array parameter values corrupted when changing parent hostgroup

Added by SAGAR SAVANT 10 days ago. Updated 10 days ago.

Status:
Ready For Testing
Priority:
Normal
Assignee:
-
Category:
-
Target version:
-
Difficulty:
Triaged:
No
Fixed in Releases:
Found in Releases:

Description

  1. Bug

When changing the parent hostgroup of a hostgroup that has a json or
array type parameter, the parameter value gets corrupted with escaped
quotes on every save.

  1. Steps to reproduce

1. Create a hostgroup HG-Parent
2. Create a child hostgroup HG-Child under HG-Parent
3. Add a json type parameter to HG-Child with value ["server","admin-access"]
4. Edit HG-Child and change its parent to a different hostgroup
5. Click Submit

  1. Expected result

Parameter value remains: ["server","admin-access"]

  1. Actual result

Parameter value becomes: [\"server\",\"admin-access\"]

  1. Root Cause

format_value_before_type_cast() in key_type.rb unconditionally calls
JSON.dump(val) even when val is already a String. During the
process_hostgroup AJAX re-render triggered by a parent change, the Ruby
Array gets serialized to a JSON String for the form field. When the
form is submitted, that String goes through JSON.dump a second time,
double-encoding it and corrupting the value permanently.

  1. Fix

Added 'unless val.is_a?(String)' guard to JSON.dump and YAML.dump
calls in format_value_before_type_cast in
app/models/concerns/key_type.rb

  1. Affected file

app/models/concerns/key_type.rb

Actions #1

Updated by The Foreman Bot 10 days ago

  • Status changed from New to Ready For Testing
  • Pull request https://github.com/theforeman/foreman/pull/11119 added
Actions

Also available in: Atom PDF