We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 944a977 commit b44ad81Copy full SHA for b44ad81
1 file changed
src/Lib.php
@@ -1350,4 +1350,26 @@ public static function wrapPlainText($input, $rowLength = 50)
1350
return implode("\n", $rows);
1351
}
1352
1353
+ /**
1354
+ * @see https://gist.github.com/gwarnants/2048791?permalink_comment_id=3438918#gistcomment-3438918
1355
+ */
1356
+ private function isBase64Encoded(string $s): bool
1357
+ {
1358
+ if ((bool) preg_match('/^[a-zA-Z0-9\/\r\n+]*={0,2}$/', $s) === false) {
1359
+ return false;
1360
+ }
1361
+
1362
+ $decoded = base64_decode($s, true);
1363
+ if ($decoded === false) {
1364
1365
1366
1367
+ $encoding = mb_detect_encoding($decoded);
1368
+ if (! in_array($encoding, ['UTF-8', 'ASCII'], true)) {
1369
1370
1371
1372
+ return $decoded !== false && base64_encode($decoded) === $s;
1373
1374
1375
0 commit comments