Psych.to_json can create invalid JSON if scalar values are not marked at quoted

Abierto
#303 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
ruby
Área
tooling

Línea de trabajo

Comienza con lib/psych/json/yaml_events.rb en la línea enlazada y reproduce el problema usando la prueba ejecutable del gist proporcionado. Traza cómo se marcan los valores escalares y las claves de mapeo durante Psych.to_json y, a continuación, añade una prueba de regresión que muestre que el documento generado es JSON válido con las claves entre comillas.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Steps to reproduce

I have created an executable test for this bug: https://gist.github.com/ianks/ba1f7175754780168c2a6618f13c95ec

I did not know whether to report this to Psych or Rails, just let me know if it belongs elsewhere and I will move the issue.

Expected behavior

Psych.to_json should emit valid JSON. Currently, not all keys are double-quoted; which although valid in JS, is not valid JSON.

Actual behavior

It emits invalid json, which can be seen in this example:

{"raw_attributes": {"id": null}, "attributes": {attributes: {"id": {name: "id", value_before_type_cast: null,
        type: {precision: null, scale: null, limit: null, range: {"begin": -2147483648,
            "end": 2147483648, "excl": true}}, original_attribute: null}}}, "new_record": true,
  "active_record_yaml_version": 1}
System configuration

Rails version: 5.0.0

Ruby version: 2.3.1

Notes

Upon further investigation, it seems the scalar types for attributes are not marked as quoted. Even if they are not marked as quoted, should we still quote the values since all keys need to be quoted in JSON? (corresponding code https://github.com/ruby/psych/blob/master/lib/psych/json/yaml_events.rb#L21)

Lenguaje dominante
Ruby
Estrellas
596
Forks
223
Merge medio
8 h 38 min
PR fusionados (30 d)
2

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de ruby/psych

Todos los issues de ruby/psych

Issues similares

Más issues de Ruby

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.