Skip to content

Commit

Permalink
Merge branch 'release/1.1.4' into v1
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Welch committed Aug 15, 2022
2 parents 9beb443 + 58fb95f commit 5e6cea0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# iCalendar Changelog

## 1.1.4 - 2022.09.15
### Changed
* Fixed an issue with multi-byte encoded content that would cause PHP to run out of memory ([#34](https://github.com/nystudio107/craft-icalendar/issues/34))

## 1.1.3 - 2022.06.29
### Changed
* Bump `johngrogg/ics-parser` to `^3.0.0` ([#32](https://github.com/nystudio107/craft-icalendar/issues/32))
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "nystudio107/craft-icalendar",
"description": "Tools for parsing & formatting the RFC 2445 iCalendar (.ics) specification",
"type": "craft-plugin",
"version": "1.1.3",
"version": "1.1.4",
"keywords": [
"craft",
"cms",
Expand Down
14 changes: 6 additions & 8 deletions src/services/Convert.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

namespace nystudio107\icalendar\services;

use craft\helpers\Template;

use craft\base\Component;

/**
Expand Down Expand Up @@ -46,11 +44,11 @@ public function rfc2445(string $text): string
// Normalize the line breaks
$text = str_replace(["\n", "\r\r\n"], self::RFC2455_EOL, $text);
// Handle rich text field output, such as from Redactor, which may have line or paragraph breaks
$text = str_replace(["</p>\r", "</P>\r"], self::RFC2455_LITERAL_NEWLINE.self::RFC2455_LITERAL_NEWLINE, $text);
$text = str_replace(["</p>\r", "</P>\r"], self::RFC2455_LITERAL_NEWLINE . self::RFC2455_LITERAL_NEWLINE, $text);
$text = str_replace(["<br>\r", "<BR>\r", "<br />\r", "<BR />\r"], self::RFC2455_LITERAL_NEWLINE, $text);
// Split the text into separate lines
$lines = explode(self::RFC2455_EOL, $text);
foreach ($lines as $key => $line) {
foreach ($lines as $key => $line) {
$result .= $this->icalSplit('', $line) . self::RFC2455_EOL;
}

Expand All @@ -77,14 +75,14 @@ protected function icalSplit(string $preamble, string $value): string
$value = html_entity_decode($value);
$value = preg_replace('/\n+/', ' ', $value);
$value = preg_replace('/\s{2,}/', ' ', $value);
$preamble_len = \strlen($preamble);
$preamble_len = mb_strlen($preamble);
$lines = [];
while (\strlen($value) > (self::MAX_OCTETS - $preamble_len)) {
while (mb_strlen($value) > (self::MAX_OCTETS - $preamble_len)) {
$space = (self::MAX_OCTETS - $preamble_len);
$mbcc = $space;
while ($mbcc) {
$line = mb_substr($value, 0, $mbcc);
$oct = \strlen($line);
$oct = mb_strlen($line);
if ($oct > $space) {
$mbcc -= $oct - $space;
} else {
Expand All @@ -99,6 +97,6 @@ protected function icalSplit(string $preamble, string $value): string
$lines[] = $value;
}

return implode(self::RFC2455_EOL.self::RFC2455_TAB, $lines);
return implode(self::RFC2455_EOL . self::RFC2455_TAB, $lines);
}
}

0 comments on commit 5e6cea0

Please sign in to comment.