MDL-74866 bennu: Fix parameter parsing

Some parameter values are wrapped by DQUOTE character.
We need to go through and get the actual value inside the quoted string.
This commit is contained in:
Huong Nguyen 2022-07-28 15:11:42 +07:00
parent a7514f231d
commit fd475bf7e8
5 changed files with 83 additions and 3 deletions

View File

@ -137,16 +137,39 @@ class behat_calendar extends behat_base {
}
/**
* Navigate to a specific date in the calendar.
* Navigate to a specific month in the calendar.
*
* @Given /^I view the calendar for "(?P<month>\d+)" "(?P<year>\d+)"$/
* @param int $month the month selected as a number
* @param int $year the four digit year
*/
public function i_view_the_calendar_for($month, $year) {
$time = make_timestamp($year, $month, 1);
$this->execute('behat_general::i_visit', ['/calendar/view.php?view=month&course=1&time='.$time]);
$this->view_the_calendar('month', 1, $month, $year);
}
/**
* Navigate to a specific date in the calendar.
*
* @Given /^I view the calendar for "(?P<day>\d+)" "(?P<month>\d+)" "(?P<year>\d+)"$/
* @param int $day the day selected as a number
* @param int $month the month selected as a number
* @param int $year the four digit year
*/
public function i_view_the_calendar_day_view(int $day, int $month, int $year) {
$this->view_the_calendar('day', $day, $month, $year);
}
/**
* View the correct calendar view with specific day
*
* @param string $type type of calendar view: month or day
* @param int $day the day selected as a number
* @param int $month the month selected as a number
* @param int $year the four digit year
*/
private function view_the_calendar(string $type, int $day, int $month, int $year) {
$time = make_timestamp($year, $month, $day);
$this->execute('behat_general::i_visit', ['/calendar/view.php?view=' . $type . '&course=1&time=' . $time]);
}
/**

View File

@ -85,3 +85,20 @@ Feature: Import and edit calendar events
And I upload "calendar/tests/fixtures/import.ics" file to "Calendar file (.ics)" filemanager
And I press "Import calendar"
And I should see "Site events"
Scenario: Import iCalendar file with parameter.
Given I log in as "admin"
And I view the calendar for "7" "2022"
And I click on "Import or export calendars" "link"
And I press "Import calendar"
And I set the following fields to these values:
| Calendar name | Test Import |
| Import from | Calendar file (.ics) |
| Type of event | User |
And I upload "calendar/tests/fixtures/import_with_parameters.ics" file to "Calendar file (.ics)" filemanager
And I press "Import calendar"
When I view the calendar for "1" "7" "2022"
Then I should see "First event"
And I should see "Description of the first event"
And I should see "Second event"
And I should see "Description of the second event"

View File

@ -0,0 +1,27 @@
BEGIN:VCALENDAR
METHOD:PUBLISH
PRODID:-//Huong Nguyen/NONSGML Moodle//EN
VERSION:2.0
BEGIN:VEVENT
UID:special_import_moodle_1
SUMMARY:First event
DESCRIPTION:Description of the first event\n
CLASS:PUBLIC
LAST-MODIFIED:20220728T034015Z
LOCATION:Vietnam
DTSTAMP:20220728T034031Z
DTSTART:20220701T070000Z
DTEND:20220701T070000Z
END:VEVENT
BEGIN:VEVENT
UID:special_import_moodle_2
SUMMARY:Second event
DESCRIPTION;ALTREP="http://moodle.com/":Description of the second event\n
CLASS:PUBLIC
LAST-MODIFIED:20220728T034021Z
LOCATION:Vietnam
DTSTAMP:20220728T034031Z
DTSTART:20220701T080000Z
DTEND:20220701T080000Z
END:VEVENT
END:VCALENDAR

View File

@ -303,6 +303,18 @@ class iCalendar_component {
$component = $this; // use the iCalendar
}
$cleanedparams = [];
// Some parameter values are wrapped by DQUOTE character.
// We need to go through and get the actual value inside the quoted string.
foreach ($params as $param => $value) {
if (preg_match('#"(?P<actualvalue>[^"]*?)"#', $value, $matches)) {
$cleanedparams[$param] = $matches['actualvalue'];
} else {
$cleanedparams[$param] = $value;
}
}
$params = $cleanedparams;
if ($component->add_property($label, $data, $params) === false) {
$this->parser_error("Failed to add property '$label' on line $key");
}

View File

@ -28,3 +28,4 @@ Changelog
9/ MDL-60391: replace create_function() with lambda function for PHP 7.2 compatibility (13 Oct 2017)
10/ MDL-62914: added handling for TZURL property (13 July 2018)
11/ MDL-67029: replace curly by square brackets for string offsets. PHP 7.4 compatibility (25 Oct 2019)
12/ MDL-74866: fixed parameter parsing if the value is wrapped by DQUOTE character (28 Jul 2022)