GithubHelp home page GithubHelp logo

dmitry-kulikov / yii2-json-editor Goto Github PK

View Code? Open in Web Editor NEW
21.0 21.0 2.0 148 KB

JSON editor widget (josdejong/jsoneditor) for Yii 2.

License: MIT License

PHP 72.49% HTML 10.26% Dockerfile 12.80% JavaScript 2.57% Ruby 1.87%
json-editor yii2-extension yii2-widgets

yii2-json-editor's People

Contributors

dmitry-kulikov avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

yii2-json-editor's Issues

Allow overriding of model attribute value using options['inputOptions']['value']

What steps will reproduce the problem?

$model->data = '"foo"';
echo $form->field($model, 'data', ['inputOptions' => ['value' => '"bar"']])
    ->widget(JsonEditor::class);

What is the expected result?

Widget should show:

"bar"

What do you get instead?

Widget shows:

"foo"

Additional info

Q A
Extension version 2.2.0
Yii version All
JSON editor version All
PHP version All
HHVM version All
Operating system All

Default value is ignored by "value" attribute of hidden input when Model is used

What steps will reproduce the problem?

$model->data = null;
echo $form->field(
    $model,
    'data',
    ['inputOptions' => ['id' => 'json-editor-hidden-input']]
)
    ->widget(
        JsonEditor::class,
        [
            'defaultValue' => '{"foo": "bar"}',
        ]
    );

In browser console execute:

$('#json-editor-hidden-input').val();

What is the expected result?

In browser console should be:

"{\"foo\": \"bar\"}"

What do you get instead?

In browser console:

""

Additional info

Normally such JS should not be used to access JSON editor, this code just shows problem.
Correct way to access JSON editor is:

var jsonEditor = window[$('#json-editor-hidden-input').data('json-editor-name')];
jsonEditor.get();

It works properly:

Object { foo: "bar" }
Q A
Extension version 2.2.0
Yii version All
JSON editor version All
PHP version All
HHVM version All
Operating system All

Widget doesn't work for tabular data input (multiple models in form)

What steps will reproduce the problem?

use kdn\yii2\JsonEditor;

$form = ActiveForm::begin();
echo $form->field($model, '[1]data[1]')->widget(JsonEditor::className());
ActiveForm::end();

What is the expected result?

Widget displays JSON.

What do you get instead?

Exception thrown:

2017-09-28 04:07:48 [127.0.0.1][4][4api8mtn0639foed1qttpb48l0][error][yii\base\UnknownPropertyException] exception 'yii\base\UnknownPropertyException' with message 'Setting unknown property: common\models\Test::[1]data[1]' in /path/to/vendor/yiisoft/yii2/base/Component.php:201

Additional info

Q A
Extension version All
Yii version All
JSON editor version All
PHP version All
HHVM version All
Operating system All

Strings '0', 'null' and '""' are valid JSON and should not be automatically replaced on {} or defaultValue

What steps will reproduce the problem?

$default = '{"foo": "bar"}';
echo JsonEditor::widget(['name' => 'test-1', 'value' => '0', 'defaultValue' => $default]);
echo JsonEditor::widget(['name' => 'test-2', 'value' => 'null', 'defaultValue' => $default]);
echo JsonEditor::widget(['name' => 'test-3', 'value' => '""', 'defaultValue' => $default]);
echo JsonEditor::widget(['name' => 'test-4', 'value' => '', 'defaultValue' => $default]);

What is the expected result?

Widgets should show:

0
null
""
{
  "foo": "bar"
}

What do you get instead?

Widgets show:

{
  "foo": "bar"
}
{}
{}
{
  "foo": "bar"
}

Additional info

Q A
Extension version 2.2.0
Yii version All
JSON editor version All
PHP version All
HHVM version All
Operating system All

Composer failed to resolve npm-asset/jsoneditor

What steps will reproduce the problem?

composer install

What is the expected result?

should install dependencies

What do you get instead?

Your requirements could not be resolved to an installable set of packages.

Problem 1
- Installation request for kdn/yii2-json-editor 1.0.2 -> satisfiable by kdn/yii2-json-editor[1.0.2].
- kdn/yii2-json-editor 1.0.2 requires npm-asset/jsoneditor 5.* -> no matching package found.

Additional info

Q A
Extension version 1.0.2
Yii version yii2-app-advanced
JSON editor version 1.0.2
PHP version 5.6.30
HHVM version
Operating system Ubuntu

Error: Invalid JSON data. If data is mysql JSON field

What steps will reproduce the problem?

  • Load data from DB via ActiveRecord Model. One of the fields has JSON type, so starting from 2.0.14 it is converted to Array while populating
  • Use Active form and use the widget, for example:
<?= $form->field($model, 'test'
        ->widget(JsonEditor::class, [
            'clientOptions' => ['modes' => ['code', 'tree']],
        ]);
    ?>

$model->test will contains array, which is a default behavior when retrieved JSON data type from db, yii do something like
$placeholder = $this->queryBuilder->bindParam(Json::encode($value), $params);

What is the expected result?

widget can read data array from JSON data type

What do you get instead?

Error: Invalid JSON data.

Additional info

Please check at JsonEditor.php
Line: 170
$encodedValue = Json::htmlEncode(Json::decode($this->value, false));

Maybe we can add a value checking first before decode the value:
$encodedValue => is_array($this->value) ? Json::htmlEncode($this->value) : Json::htmlEncode(Json::decode($this->value, false));

Q A
Extension version 2.2.0
Yii version 2.0.27
JSON editor version
PHP version 5.3
HHVM version
Operating system

Allow overriding of model attribute value using explicit setting of value property for widget

What steps will reproduce the problem?

$model->data = '"foo"';
echo $form->field($model, 'data', ['inputOptions' => ['value' => '"bar"']])
    ->widget(JsonEditor::class, ['value' => '"test"']);

What is the expected result?

Widget should show:

"test"

What do you get instead?

Widget shows:

"foo"

Additional info

Q A
Extension version 2.2.0
Yii version All
JSON editor version All
PHP version All
HHVM version All
Operating system All

Widget doesn't work if JSON contains <script> tag

What steps will reproduce the problem?

use kdn\yii2\JsonEditor;

echo JsonEditor::widget(
    [
        'name' => 'editor',
        'value' => '{"script": "<script type=\"text/javascript\">alert(\"XSS\");</script>"}',
    ]
);

What is the expected result?

Widget displays JSON.

What do you get instead?

Widget not shown. Error in browser console:

SyntaxError: unterminated string literal

Additional info

Q A
Extension version All
Yii version All
JSON editor version All
PHP version All
HHVM version All
Operating system All

Looks like <script> tag is not properly escaped. This bug may produce risk of XSS vulnerability.

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.