r100796 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100795‎ | r100796 | r100797 >
Date:06:41, 26 October 2011
Author:questpc
Status:deferred
Tags:
Comment:
Fix is_numeric() issues. That also limits question ids, proposal ids and CSS width / height values to max 9999 (it is realistically enough).
Modified paths:
  • /trunk/extensions/QPoll/includes/qp_functionshook.php (modified) (history)
  • /trunk/extensions/QPoll/qp_user.php (modified) (history)
  • /trunk/extensions/QPoll/view/proposal/qp_textquestionproposalview.php (modified) (history)
  • /trunk/extensions/QPoll/view/question/qp_textquestionview.php (modified) (history)

Diff [purge]

Index: trunk/extensions/QPoll/qp_user.php
@@ -144,6 +144,11 @@
145145 const ERROR_MISSED_TITLE = 1;
146146 const ERROR_INVALID_ADDRESS = 2;
147147
 148+ # matches string which contains integer number in range 0..9999
 149+ const PREG_NON_NEGATIVE_INT4_MATCH = '/^(?:\d|[1-9]\d{1,3})$/';
 150+ # matches string which contains integer number in range 1..9999
 151+ const PREG_POSITIVE_INT4_MATCH = '/^[1-9]\d{0,3}$/';
 152+
148153 static $pollTag = 'qpoll';
149154 static $interpTag = 'qpinterpret';
150155 # parser $interpTag hook output market list
Index: trunk/extensions/QPoll/includes/qp_functionshook.php
@@ -69,7 +69,7 @@
7070 # get poll's proposal choice
7171 $this->proposal_id = trim( $frame->expand( $args[ 2 ] ) );
7272 $this->error_message = 'invalid_proposal_id';
73 - if ( is_numeric( $this->proposal_id ) && $this->proposal_id >= 0 ) {
 73+ if ( preg_match( qp_Setup::PREG_NON_NEGATIVE_INT4_MATCH, $this->proposal_id ) ) {
7474 $this->defaultProposalText = isset( $args[ 3 ] ) ? trim( $frame->expand( $args[ 3 ] ) ) : '';
7575 $this->proposal_id = intval( $this->proposal_id );
7676 $this->error_message = 'missing_proposal_id';
@@ -88,7 +88,7 @@
8989 function getQuestionData( $qid ) {
9090 $this->question_id = $qid;
9191 $this->error_message = 'invalid_question_id';
92 - if ( is_numeric( $this->question_id ) ) {
 92+ if ( preg_match( qp_Setup::PREG_POSITIVE_INT4_MATCH, $this->question_id ) ) {
9393 $this->question_id = intval( $this->question_id );
9494 $this->pollStore->loadQuestions();
9595 $this->pollStore->setLastUser( qp_Setup::getCurrUserName(), false );
Index: trunk/extensions/QPoll/view/proposal/qp_textquestionproposalview.php
@@ -73,12 +73,8 @@
7474 $val = &$viewtoken->attributes[$measurable];
7575 if ( $val === null ) {
7676 $val = 0;
77 - } elseif ( is_numeric( $val ) ) {
78 - if ( ( $val = intval( $val ) ) < 1 ) {
79 - $val = 0;
80 - }
81 - } else {
82 - $val = 'auto';
 77+ } elseif ( $val !== 'auto' ) {
 78+ $val = preg_match( qp_Setup::PREG_POSITIVE_INT4_MATCH, $val ) ? intval( $val ) : 0;
8379 }
8480 }
8581 $this->viewtokens[] = $viewtoken;
Index: trunk/extensions/QPoll/view/question/qp_textquestionview.php
@@ -284,9 +284,8 @@
285285 $this->transposed = strpos( $layout, 'transpose' ) !== false;
286286 }
287287 if ( $textwidth !== null ) {
288 - if ( is_numeric( $textwidth ) &&
289 - $textwidth = intval( $textwidth ) > 0 ) {
290 - $this->textInputStyle = 'width:' . $textwidth . 'em;';
 288+ if ( preg_match( qp_Setup::PREG_POSITIVE_INT4_MATCH, $textwidth ) ) {
 289+ $this->textInputStyle = "width:{$textwidth}em;";
291290 } elseif ( $textwidth === 'auto' ) {
292291 $this->textInputStyle = 'width:auto;';
293292 }

Status & tagging log