Skip to content

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

Closed
@ivordurham

Description

@ivordurham

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions