Skip to content

Commit

Permalink
Remove the "string" return type constraint from "filter" function
Browse files Browse the repository at this point in the history
The filter function can actually return any data type. Because a) the
signature for the base class doesn't include a return type constraint,
and b) the legacy behavior for text filters is to return any argument
that is not a string as-is (thus, returning the same type as the
original value).

Add some additional test cases to make sure we don't re-introduce the
same problem in the future (assuming the base class function signature
doesn't change, of course).

[Fixes: #45]
  • Loading branch information
iarenaza committed Jan 31, 2024
1 parent eb53872 commit 0d2fedf
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 3 deletions.
44 changes: 44 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added
- This CHANGELOG.

### Fixed
- [#45] Exception: Return value must be of type string, null returned

## [2.0.0] - 2022-12-17

### Added
- Early checks for "text" that cannot be filtered or is not worth filtering (e.g., non-strings, or empty strings).
- [#35] Addded GitHub Actions and information in README.md, contributed by Luca Bösch.

### Changed
- [#32] **[BREAKING CHANGE]** Updated the unit test machinery to be compatible with Moodle 3.11 and later. The new machinery is incompatible with Moodle 3.10 and later, making this a breaking change.

### Fixed
- Fixed some Moodle Code Checker and Documentation Checker warnings.

### Security
- [#39] MDL-77525 apply multilang2 before text formatting and cleaning

[UNRELEASED]: https://github.com/iarenaza/moodle-filter_multilang2/compare/2.0.0...HEAD
[2.0.0]: https://github.com/iarenaza/moodle-filter_multilang2/compare/1.1.2...2.0.0
[1.1.2]: https://github.com/iarenaza/moodle-filter_multilang2/compare/1.1.1...1.1.2
[1.1.1]: https://github.com/iarenaza/moodle-filter_multilang2/compare/1.0.1...1.1.1
[1.0.5]: https://github.com/iarenaza/moodle-filter_multilang2/compare/1.0.4...1.0.5
[1.0.4]: https://github.com/iarenaza/moodle-filter_multilang2/compare/1.0.3...1.0.4
[1.0.3]: https://github.com/iarenaza/moodle-filter_multilang2/compare/1.0.2...1.0.3
[1.0.2]: https://github.com/iarenaza/moodle-filter_multilang2/compare/1.0.1...1.0.2
[1.0.1]: https://github.com/iarenaza/moodle-filter_multilang2/compare/1.0...1.0.1
[1.0]: https://github.com/iarenaza/moodle-filter_multilang2/releases/tag/1.0
[#45]: https://github.com/iarenaza/moodle-filter_multilang2/pull/45
[#39]: https://github.com/iarenaza/moodle-filter_multilang2/pull/39
[#35]: https://github.com/iarenaza/moodle-filter_multilang2/issues/35
[#32]: https://github.com/iarenaza/moodle-filter_multilang2/issues/32
2 changes: 1 addition & 1 deletion filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function filter_stage_string(string $text, array $options): string {
* @param array $options The filter options.
* @return string The filtered text for this multilang block.
*/
public function filter($text, array $options = array()): string {
public function filter($text, array $options = array()) {

if (!is_string($text) || empty($text)) {
// Non-string data can not be filtered anyway.
Expand Down
16 changes: 15 additions & 1 deletion tests/actual_test_cases.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,20 @@ function multilang2_actual_test_cases(): array {
'{mlang ,es}Bad filter syntax{mlang}',
'es',
],
[
null,
null,
'es',
],
[
123,
123,
'es',
],
[
123.0,
123.0,
'es',
],
];
}

2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2022120900; // The current plugin version (Date: YYYYMMDDXX).
$plugin->version = 2024013100; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2021051700; // Requires this Moodle version.
$plugin->component = 'filter_multilang2'; // Full name of the plugin (used for diagnostics).
$plugin->release = '2.0.0';
Expand Down

0 comments on commit 0d2fedf

Please sign in to comment.