Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

A mailto hyperlink emits the url text instead of the hyperlink in Html output #4316

Closed
1 of 8 tasks
ivordurham opened this issue Jan 13, 2025 · 0 comments · Fixed by #4322
Closed
1 of 8 tasks

A mailto hyperlink emits the url text instead of the hyperlink in Html output #4316

ivordurham opened this issue Jan 13, 2025 · 0 comments · Fixed by #4322

Comments

@ivordurham
Copy link

This is:

- [X] a bug report
- [ ] a feature request
- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

Setting a mailto hyperlink on a cell replaces the cell contents with the mailto url when writing HTML.

The bug appears to be this line in Html.php:

if ($parseScheme === 1 && !in_array($matches[1], ['http', 'https', 'file', 'ftp', 's3'], true)) {

The problem is corrected by adding mailto to the list of url schemes:

if ($parseScheme === 1 && !in_array($matches[1], ['http', 'https', 'file', 'ftp', 's3','mailto'], true)) {

What is the expected behavior?

Output:

Mail Me!

What is the current behavior?

Outputs:

mailto:me@example.com

What are the steps to reproduce?

Please provide a Minimal, Complete, and Verifiable example of code that exhibits the issue without relying on an external Excel file or a web server:

<?php
require __DIR__ . '/vendor/autoload.php';

$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();

$worksheet = $spreadsheet->getActiveSheet();

$worksheet->setCellValueByColumnAndRow(1, 1, 'Mail Me!');

$worksheet->getCell('A1')->getHyperlink()->setUrl('mailto:me@example.com');

$writer = PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Html');

$writer->save('php://output');
?>

If this is an issue with reading a specific spreadsheet file, then it may be appropriate to provide a sample file that demonstrates the problem; but please keep it as small as possible, and sanitize any confidential information before uploading.

What features do you think are causing the issue

  • Reader
  • Writer
  • Styles
  • Data Validations
  • Formula Calculations
  • Charts
  • AutoFilter
  • Form Elements

Does an issue affect all spreadsheet file formats? If not, which formats are affected?

Only affects HTML output

Which versions of PhpSpreadsheet and PHP are affected?

At least 1.28 onwards

oleibman added a commit to oleibman/PhpSpreadsheet that referenced this issue Jan 15, 2025
Fix PHPOffice#4316. A security patch white-listed the protocols that could be used in a hyperlink. This PR adds mailto to the list.
@oleibman oleibman mentioned this issue Jan 15, 2025
11 tasks
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant