Project

General

Profile

Actions

Backport(バックポート) #2143

closed

Cannot modify Custom CSS in an empty character string (カスタムCSSを空にして保存することができない)

Added by Minoru Takai over 13 years ago. Updated over 13 years ago.

Status:
Fixed(完了)
Priority:
Normal(通常)
Assignee:
Target version:
Start date:
2010-08-02
Due date:
% Done:

100%

Estimated time:

Description

Overview (概要)

管理画面からカスタムCSSを編集する際、当該テキストエリア name="css[css]" の値が空文字列であると(つまりカスタムCSSを空にしようとしても)保存の処理が行われない。

また、既に記述しているカスタムCSSを削除しようと思った場合に、その保存が失敗したことすら示されておらず、管理者を混乱させてしまう(カスタムCSSのクリアが成功したように見えるが実際にはクリアされていない)。

Causes (原因)

管理画面にあるカスタムCSSのフォームは次のフォームクラスでバリデートされている。

  • apps/pc_backend/modules/design/lib/opCustomCssForm.class.php
    11-class opCustomCssForm extends sfForm
    12-{
    13-  public function configure()
    14-  {
    15-    $this->setWidget('css', new sfWidgetFormTextarea(array(), array('rows' => '20', 'cols' => '70')));
    16-    $this->setValidator('css', new opValidatorString());
    17-
    18-    $this->setDefault('css', Doctrine::getTable('SnsConfig')->get('customizing_css'));
    19-
    20-    $this->widgetSchema->setNameFormat('css[%s]');
    21-  }
    22-
    23-  public function save()
    24-  {
    25-    Doctrine::getTable('SnsConfig')->set('customizing_css', $this->getValue('css'));
    26-    opToolkit::clearCache();
    27-  }
    28-}
    

この 16 行目では opValidatorString() で入力値のバリデートを行っているが、

  • lib/validator/opValidatorString.class.php
    19-class opValidatorString extends sfValidatorString
    20-{
    21-  protected function configure($options = array(), $messages = array())
    22-  {
    23-    parent::configure($options, $messages);
    24-
    25-    $this->addOption('ltrim', false);
    26-    $this->addOption('rtrim', false);
    27-  }
    
  • lib/vendor/symfony/lib/validator/sfValidatorString.class.php
  • lib/vendor/symfony/lib/validator/sfValidatorBase.class.php
    51-  public function __construct($options = array(), $messages = array())
    52-  {
    53-    $this->options  = array_merge(array('required' => true, 'trim' => false, 'empty_value' => null), $this->options);
    

opValidatorString() を呼んだ場合は ('required' => false) を要素として持つ array() を引数として与えないと、空文字列の場合に「必須項目である」として弾かれてしまう。

Way to fix (修正方針)

  • opValidatorString(array('required' => false)) のようにしてバリデータの required を false とする
    index 531b1d9..bb6013c 100644
    --- a/apps/pc_backend/modules/design/lib/opCustomCssForm.class.php
    +++ b/apps/pc_backend/modules/design/lib/opCustomCssForm.class.php
    @@ -13,7 +13,7 @@ class opCustomCssForm extends sfForm
       public function configure()
       {
         $this->setWidget('css', new sfWidgetFormTextarea(array(), array('rows' => '20', 'cols' => '70')));
    -    $this->setValidator('css', new opValidatorString());
    +    $this->setValidator('css', new opValidatorString(array('required' => false)));
    
         $this->setDefault('css', Doctrine::getTable('SnsConfig')->get('customizing_css'));
    

Notes (補足)

  • 現時点でも、「半角スペースのみ」や「改行のみ」での保存は可能であり( trim は一切行なわれておらず)、空文字列の保存のみが失敗するような動作となっている
    • 改行のみで保存した場合は、改行が1つ省かれて保存されるようである(この挙動はこのチケットで扱うべき問題ではないと考えられる)
  • また本件の問題にはならないが、 apps/pc_frontend/templates/_layout.php 等では以下のように記述されている(カスタムCSSの文字列内容を直接真偽値として扱っている)ため、カスタムCSSの内容が空である場合には、カスタムCSSの読み込み自体が行なわれない。
    9:<?php if (Doctrine::getTable('SnsConfig')->get('customizing_css')): ?>
    10-<link rel="stylesheet" type="text/css" href="<?php echo url_for('@customizing_css') ?>" />
    11-<?php endif; ?>
    

Related issues 1 (0 open1 closed)

Related to OpenPNE 3 - Bug(バグ) #1462: Cannot modify Custom CSS in an empty character string (カスタムCSSを空にして保存することができない)Fixed(完了)Youichi Kimura2010-08-02

Actions
Actions #1

Updated by Minoru Takai over 13 years ago

  • Target version changed from OpenPNE 3.7.0 to OpenPNE 3.4.13
Actions #2

Updated by Minoru Takai over 13 years ago

  • Status changed from New(新規) to Accepted(着手)
  • Assignee set to Minoru Takai

着手します。

Actions #3

Updated by Youichi Kimura over 13 years ago

  • Status changed from Accepted(着手) to Pending Review(レビュー待ち)
  • % Done changed from 100 to 50

更新履歴 27774fe6e7b9ba1bd9ca713911023e2b2a8e54e4 で適用されました。

Actions #4

Updated by Yuma Sakata over 13 years ago

テストOKです。

Actions #5

Updated by Shinichi Urabe over 13 years ago

  • Status changed from Pending Review(レビュー待ち) to Fixed(完了)
  • % Done changed from 50 to 100

master のバグチケットのソースと差異がなく、OpenPNE 3.4 のソース修正としても問題ない修正だと思いますので、チケットは完了にします

Actions

Also available in: Atom PDF