Skip to content

Conversation

@dtpop
Copy link
Member

@dtpop dtpop commented Dec 11, 2025

Verhindert Deprecated: htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated in redaxo\src\addons\mform\ytemplates\bootstrap\value.custom_link.tpl.php on line 6

Summary by CodeRabbit

Bug Fixes

  • Verbesserung der Wertanzeige: Leere oder falsy Werte werden nun korrekt als leere Strings dargestellt, anstatt potenziell zu unerwünschten Anzeigewerten zu führen.

✏️ Tip: You can customize this high-level summary in your review settings.

Verhindert Deprecated: htmlspecialchars(): Passing null to parameter FriendsOfREDAXO#1 ($string) of type string is deprecated in redaxo\src\addons\mform\ytemplates\bootstrap\value.custom_link.tpl.php on line 6
@coderabbitai
Copy link

coderabbitai bot commented Dec 11, 2025

Moin! 👋

Walkthrough

Eine einzelne Datei wurde angepasst, um die Wertezuweisung defensiver zu gestalten. Der getValue()-Aufruf wird nun mit einem Fallback auf einen leeren String versehen, falls das Ergebnis falsy ist. Die Logik und der Kontrollfluss bleiben unverändert.

Changes

Cohort / Datei(en) Zusammenfassung der Änderungen
Custom Link Widget Value
ytemplates/bootstrap/value.custom_link.tpl.php
Wertezuweisung mit Fallback-Operator: htmlspecialchars($this->getValue() ?: '') stellt sicher, dass statt null oder falsy-Werten ein leerer String verwendet wird.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive Der Titel ist vage und generisch; er beschreibt nur den geänderten Dateinamen, ohne die tatsächliche Änderung oder deren Zweck zu erläutern. Der Titel sollte spezifischer sein und die Hauptänderung beschreiben, z.B. 'Fix deprecated htmlspecialchars() warning in value.custom_link.tpl.php' oder 'Handle null values in custom_link template'.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9f2b59f and 5083a1c.

📒 Files selected for processing (1)
  • ytemplates/bootstrap/value.custom_link.tpl.php (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
ytemplates/bootstrap/value.custom_link.tpl.php (1)
lib/MForm/DTO/MFormItem.php (1)
  • getValue (74-77)

$categoryId = 0;
$name = $this->getFieldName();
$value = htmlspecialchars($this->getValue());
$value = htmlspecialchars($this->getValue() ?: '');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# Find the file and check its content
find . -name "MFormItem*" -o -name "*MFormItem*" | head -20

Repository: FriendsOfREDAXO/mform

Length of output: 137


🏁 Script executed:

# Search for MFormItem class definition to verify return type
rg "class MFormItem" -A 30

Repository: FriendsOfREDAXO/mform

Length of output: 4629


🏁 Script executed:

# Look at the file in question
cat -n ytemplates/bootstrap/value.custom_link.tpl.php

Repository: FriendsOfREDAXO/mform

Length of output: 1880


🏁 Script executed:

# Check git history to see the original code before this change
cd . && git log --oneline -20 -- ytemplates/bootstrap/value.custom_link.tpl.php 2>/dev/null || echo "Git history not available"

Repository: FriendsOfREDAXO/mform

Length of output: 105


🏁 Script executed:

# Search for getValue() method definition in MFormItem
rg "public.*function getValue" -B 2 -A 5

Repository: FriendsOfREDAXO/mform

Length of output: 868


🏁 Script executed:

# Get the actual git diff to see what changed
git show 5083a1c -- ytemplates/bootstrap/value.custom_link.tpl.php 2>/dev/null || git diff HEAD~1 -- ytemplates/bootstrap/value.custom_link.tpl.php 2>/dev/null || echo "Cannot retrieve git diff"

Repository: FriendsOfREDAXO/mform

Length of output: 2239


🏁 Script executed:

# Search for where this template is used or rendered
rg "value.custom_link.tpl.php" -B 3 -A 3

Repository: FriendsOfREDAXO/mform

Length of output: 562


🏁 Script executed:

# Check if there are any tests or usage examples
find . -name "*custom_link*" -type f | head -20

Repository: FriendsOfREDAXO/mform

Length of output: 269


🏁 Script executed:

# Look at the rex_var_custom_link widget to understand what it expects
rg "class rex_var_custom_link" -A 20

Repository: FriendsOfREDAXO/mform

Length of output: 1504


🏁 Script executed:

# Search for getWidget method to understand the expected $value parameter
rg "function getWidget" -B 2 -A 15

Repository: FriendsOfREDAXO/mform

Length of output: 3299


🏁 Script executed:

# Check if this file existed before in a different location or was completely new
git log --all --full-history -- ytemplates/bootstrap/value.custom_link.tpl.php | head -20

Repository: FriendsOfREDAXO/mform

Length of output: 827


🏁 Script executed:

# Check the field definition for custom_link to see if it's multi-value
rg "custom_link" -B 3 -A 10 | grep -A 10 "class.*custom_link\|type.*custom_link" | head -40

Repository: FriendsOfREDAXO/mform

Length of output: 3152


🏁 Script executed:

# Check if arrays are ever actually passed to this template by looking at how MFormItem is populated for custom_link
rg "custom_link" lib/yform/value/ -B 2 -A 10

Repository: FriendsOfREDAXO/mform

Length of output: 4099


🏁 Script executed:

# Check the classic template version to see if it has similar code
cat -n ytemplates/classic/value.custom_link.tpl.php

Repository: FriendsOfREDAXO/mform

Length of output: 1948


🏁 Script executed:

# Check if classic template also has the same issue and when it was last touched
git log --oneline -- ytemplates/classic/value.custom_link.tpl.php | head -10

Repository: FriendsOfREDAXO/mform

Length of output: 105


🏁 Script executed:

# Verify the actual differences between bootstrap and classic templates
diff -u ytemplates/classic/value.custom_link.tpl.php ytemplates/bootstrap/value.custom_link.tpl.php | head -30

Repository: FriendsOfREDAXO/mform

Length of output: 1285


🏁 Script executed:

# Check if custom_link value field is defined as multi-value or single-value
rg "db_type.*text" lib/yform/value/custom_link.php -B 5 -A 2

Repository: FriendsOfREDAXO/mform

Length of output: 470


Moin Verwende Null-Coalescing statt Elvis-Operator und aktualisiere auch classic-Template

Die Änderung mit ?: '' funktioniert zur Vermeidung des Deprecation-Warnings, aber ?? wäre die bessere Wahl. Der Elvis-Operator ?: behandelt alle falsy Werte gleich (z.B. 0 wird zu ''), während ?? nur null abfängt. Für ein Link-Feld ist 0 zwar keine typische Eingabe, aber ?? ist semantisch präziser:

-$value = htmlspecialchars($this->getValue() ?: '');
+$value = htmlspecialchars($this->getValue() ?? '');

Zusätzlich: Das ytemplates/classic/value.custom_link.tpl.php-Template hat das identische Problem und wurde nicht aktualisiert. Die gleiche Änderung sollte dort ebenfalls vorgenommen werden.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
$value = htmlspecialchars($this->getValue() ?: '');
$value = htmlspecialchars($this->getValue() ?? '');
🤖 Prompt for AI Agents
In ytemplates/bootstrap/value.custom_link.tpl.php around line 6, the code uses
the Elvis operator ($this->getValue() ?: '') which converts all falsy values
(e.g. 0) to an empty string; change this to use the null-coalescing operator
($this->getValue() ?? '') so only null falls back to ''. Also apply the
identical replacement in ytemplates/classic/value.custom_link.tpl.php at the
corresponding line to keep both templates consistent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant