Skip to content

Commit

Permalink
Add validation for static page slugs. (#1703) (#1705)
Browse files Browse the repository at this point in the history
  • Loading branch information
melaniekung authored Nov 7, 2023
1 parent 6cb1412 commit 9bd6f13
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions apps/qubit/modules/staticpage/templates/editSuccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
<?php echo render_field($form->title, $resource); ?>

<?php if ($resource->isProtected()) { ?>
<?php echo $form->slug->renderRow(['class' => 'readOnly', 'disabled' => 'disabled']); ?>
<?php echo $form->slug->renderRow([['class' => 'readOnly'], 'disabled' => 'disabled']); ?>
<?php } else { ?>
<?php echo $form->slug->renderRow(); ?>
<?php echo $form->slug->renderRow(['pattern' => '^[a-zA-Z][a-zA-Z0-9\-_]*$']); ?>
<?php } ?>

<?php echo render_field($form->content, $resource, ['class' => 'resizable']); ?>
Expand Down
4 changes: 4 additions & 0 deletions lib/helper/QubitHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ function render_field($field, $resource = null, array $options = [])
$div = null;
$culture = sfContext::getInstance()->user->getCulture();

if (isset($options['pattern'])) {
$options['pattern'] = '^[a-zA-Z][a-zA-Z0-9\-_]*$';
}

$resourceRaw = sfOutputEscaper::unescape($resource);
if (isset($resourceRaw) && $culture != $resourceRaw->sourceCulture) {
if ($resourceRaw instanceof QubitSetting) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
<?php echo render_field($form->title, $resource); ?>

<?php if ($resource->isProtected()) { ?>
<?php echo render_field($form->slug, null, ['disabled' => 'disabled']); ?>
<?php echo render_field($form->slug, null, ['disabled' => 'disabled', 'type' => 'url']); ?>
<?php } else { ?>
<?php echo render_field($form->slug); ?>
<?php echo render_field($form->slug, null, ['pattern' => '^[a-zA-Z0-9\-_]+$']); ?>
<?php } ?>

<?php echo render_field($form->content, $resource); ?>
Expand Down

0 comments on commit 9bd6f13

Please sign in to comment.