Skip to content

Commit

Permalink
Merge pull request #1773 from magento-engcom/2.2-develop-prs
Browse files Browse the repository at this point in the history
Public Pull Requests

#12328 9742: Default welcome message returns after being deleted #9742 by @RomaKis
#12253 New validation: 3bytes characters filter (4 bytes characters cannot be stored using UTF8) by @KarlDeux
#12133 Fix for issue 12127: Single quotation marks are now decoded properly in admin attribute option input fields by @erfanimani
#11389 Attribute category_ids issue by @manuelson

Fixed Public Issues

#9742 Default welcome message returns after being deleted
#12058 Can't save emoji in custom product options
#12127 Apostrophe in attribute option value in admin is not handled properly
#11341 Attribute category_ids issue
  • Loading branch information
Oleksii Korshenko authored Nov 28, 2017
2 parents 3d628f8 + a0a2474 commit 6862632
Show file tree
Hide file tree
Showing 10 changed files with 176 additions and 6 deletions.
6 changes: 3 additions & 3 deletions app/code/Magento/Catalog/Block/Product/View/Attributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,16 @@ public function getAdditionalData(array $excludeAttr = [])
$attributes = $product->getAttributes();
foreach ($attributes as $attribute) {
if ($attribute->getIsVisibleOnFront() && !in_array($attribute->getAttributeCode(), $excludeAttr)) {
$value = $attribute->getFrontend()->getValue($product);

if (is_array($value = $attribute->getFrontend()->getValue($product))) {
continue;
}
if (!$product->hasData($attribute->getAttributeCode())) {
$value = __('N/A');
} elseif ((string)$value == '') {
$value = __('No');
} elseif ($attribute->getFrontendInput() == 'price' && is_string($value)) {
$value = $this->priceCurrency->convertAndFormat($value);
}

if ($value instanceof Phrase || (is_string($value) && strlen($value))) {
$data[$attribute->getAttributeCode()] = [
'label' => __($attribute->getStoreLabel()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ $stores = $block->getStoresSortedBySortOrder();
$values = [];
foreach($block->getOptionValues() as $value) {
$value = $value->getData();
$values[] = is_array($value) ? array_map("htmlspecialchars_decode", $value) : $value;
$values[] = is_array($value) ? array_map(function($str) {
return htmlspecialchars_decode($str, ENT_QUOTES);
}, $value) : $value;
}
?>
<script type="text/x-magento-init">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ $class = ($_option->getIsRequire()) ? ' required' : '';
if ($_option->getMaxCharacters()) {
$_textValidate['maxlength'] = $_option->getMaxCharacters();
}
$_textValidate['validate-no-utf8mb4-characters'] = true;
?>
<input type="text"
id="options_<?= /* @escapeNotVerified */ $_option->getId() ?>_text"
Expand All @@ -47,6 +48,7 @@ $class = ($_option->getIsRequire()) ? ' required' : '';
if ($_option->getMaxCharacters()) {
$_textAreaValidate['maxlength'] = $_option->getMaxCharacters();
}
$_textAreaValidate['validate-no-utf8mb4-characters'] = true;
?>
<textarea id="options_<?= /* @escapeNotVerified */ $_option->getId() ?>_text"
class="product-custom-option"
Expand Down
7 changes: 5 additions & 2 deletions app/code/Magento/Theme/Model/Design/Config/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,13 @@ public function load($scope, $scopeId)
$scopeId,
$fieldData->getFieldConfig()
);
if ($value !== null) {
$fieldData->setValue($value);

if ($value === null) {
$value = '';
}
$fieldData->setValue($value);
}

return $designConfig;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Theme\Model\Design;

/**
* Test for \Magento\Theme\Model\Design\Config\Storage.
*/
class ConfigTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Theme\Model\Design\Config\Storage
*/
private $storage;

protected function setUp()
{
$this->storage = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Theme\Model\Design\Config\Storage::class
);
}

/**
* Test design/header/welcome if it is saved in db as empty(null) it should be shown on backend as empty.
*
* @magentoDataFixture Magento/Theme/_files/config_data.php
*/
public function testLoad()
{
$data = $this->storage->load('stores', 1);
foreach ($data->getExtensionAttributes()->getDesignConfigData() as $configData) {
if ($configData->getPath() == 'design/header/welcome') {
$this->assertSame('', $configData->getValue());
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

use Magento\Config\Model\Config\Factory;
use Magento\TestFramework\Helper\Bootstrap;

$objectManager = Bootstrap::getObjectManager();

/** @var Factory $configFactory */
$configFactory = $objectManager->create(Factory::class);
/** @var \Magento\Config\Model\Config $config */
$config = $configFactory->create();
$config->setScope('stores');
$config->setStore('default');
$config->setDataByPath('design/header/welcome', null);
$config->save();
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
/** @var \Magento\Framework\App\ResourceConnection $resource */
$resource = $objectManager->get(\Magento\Framework\App\ResourceConnection::class);
$connection = $resource->getConnection();
$tableName = $resource->getTableName('core_config_data');

$connection->query("DELETE FROM $tableName WHERE path = 'design/header/welcome';");
72 changes: 72 additions & 0 deletions dev/tests/js/jasmine/tests/lib/mage/validation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,76 @@ define([
)).toEqual(true);
});
});

describe('Testing 3 bytes characters only policy (UTF-8)', function () {
it('rejects data, if any of the characters cannot be stored using UTF-8 collation', function () {
expect($.validator.methods['validate-no-utf8mb4-characters'].call(
$.validator.prototype, '😅😂', null
)).toEqual(false);
expect($.validator.methods['validate-no-utf8mb4-characters'].call(
$.validator.prototype, '😅 test 😂', null
)).toEqual(false);
expect($.validator.methods['validate-no-utf8mb4-characters'].call(
$.validator.prototype, '💩 👻 💀', null
)).toEqual(false);
});

it('approves data, if all the characters can be stored using UTF-8 collation', function () {
expect($.validator.methods['validate-no-utf8mb4-characters'].call(
$.validator.prototype, '', null
)).toEqual(true);
expect($.validator.methods['validate-no-utf8mb4-characters'].call(
$.validator.prototype, '!$-_%ç&#?!', null
)).toEqual(true);
expect($.validator.methods['validate-no-utf8mb4-characters'].call(
$.validator.prototype, '1234567890', null
)).toEqual(true);
expect($.validator.methods['validate-no-utf8mb4-characters'].call(
$.validator.prototype, ' ', null
)).toEqual(true);
expect($.validator.methods['validate-no-utf8mb4-characters'].call(
$.validator.prototype, 'test', null
)).toEqual(true);
expect($.validator.methods['validate-no-utf8mb4-characters'].call(
$.validator.prototype, 'испытание', null
)).toEqual(true);
expect($.validator.methods['validate-no-utf8mb4-characters'].call(
$.validator.prototype, 'тест', null
)).toEqual(true);
expect($.validator.methods['validate-no-utf8mb4-characters'].call(
$.validator.prototype, 'փորձարկում', null
)).toEqual(true);
expect($.validator.methods['validate-no-utf8mb4-characters'].call(
$.validator.prototype, 'परीक्षण', null
)).toEqual(true);
expect($.validator.methods['validate-no-utf8mb4-characters'].call(
$.validator.prototype, 'テスト', null
)).toEqual(true);
expect($.validator.methods['validate-no-utf8mb4-characters'].call(
$.validator.prototype, '테스트', null
)).toEqual(true);
expect($.validator.methods['validate-no-utf8mb4-characters'].call(
$.validator.prototype, '测试', null
)).toEqual(true);
expect($.validator.methods['validate-no-utf8mb4-characters'].call(
$.validator.prototype, '測試', null
)).toEqual(true);
expect($.validator.methods['validate-no-utf8mb4-characters'].call(
$.validator.prototype, 'ทดสอบ', null
)).toEqual(true);
expect($.validator.methods['validate-no-utf8mb4-characters'].call(
$.validator.prototype, 'δοκιμή', null
)).toEqual(true);
expect($.validator.methods['validate-no-utf8mb4-characters'].call(
$.validator.prototype, 'اختبار', null
)).toEqual(true);
expect($.validator.methods['validate-no-utf8mb4-characters'].call(
$.validator.prototype, 'تست', null
)).toEqual(true);
expect($.validator.methods['validate-no-utf8mb4-characters'].call(
$.validator.prototype, 'מִבְחָן', null
)).toEqual(true);
});
});

});
1 change: 1 addition & 0 deletions lib/web/i18n/en_US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ Submit,Submit
"Password cannot be the same as email address.","Password cannot be the same as email address."
"Please fix this field.","Please fix this field."
"Please enter a valid email address.","Please enter a valid email address."
"Please remove invalid characters: {0}.", "Please remove invalid characters: {0}."
"Please enter a valid URL.","Please enter a valid URL."
"Please enter a valid date (ISO).","Please enter a valid date (ISO)."
"Please enter only digits.","Please enter only digits."
Expand Down
18 changes: 18 additions & 0 deletions lib/web/mage/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,24 @@
$.mage.__('Please enter at least {0} characters')
],

/* detect chars that would require more than 3 bytes */
'validate-no-utf8mb4-characters': [
function (value) {
var validator = this,
message = $.mage.__('Please remove invalid characters: {0}.'),
matches = value.match(/(?:[\uD800-\uDBFF][\uDC00-\uDFFF])/g),
result = matches === null;

if (!result) {
validator.charErrorMessage = message.replace('{0}', matches.join());
}

return result;
}, function () {
return this.charErrorMessage;
}
],

/* eslint-disable max-len */
'email2': [
function (value, element) {
Expand Down

0 comments on commit 6862632

Please sign in to comment.