syncfusion / flutter-widgets

Syncfusion Flutter widgets libraries include high quality UI widgets and file-format packages to help you create rich, high-quality applications for iOS, Android, and web from a single code base.
1.6k stars 783 forks source link

[syncfusion_flutter_pdfviewer] Issue in parsing `tel:` urls from PDFs #2180

Open jonl-percsolutions-com opened 1 day ago

jonl-percsolutions-com commented 1 day ago

Bug description

When a pdf contains both https: and tel: links. Possibly even just tel: links, the parsing of the link fails in PDFViewerCanvas.

The code pasted below in the stack traces breaks and seems unnecessary. Let the url parse it and the platform handle it.

Steps to reproduce

  1. open a pdf with tel: and mixed https links
  2. attempt to open the tel: link
  3. see it cause an error

Code sample

fixed code

             //Just parse the url, be done with it and let the platform handle it!
              final Uri url = Uri.parse(_pdfTextWebLink!.url);
              _showHyperLinkDialog(url);
              markNeedsPaint();
              break;

Screenshots or Video

N/a

Stack Traces

https://github.com/syncfusion/flutter-widgets/blob/master/packages/syncfusion_flutter_pdfviewer/lib/src/control/pdfviewer_canvas.dart

              final bool isMailID =
                  RegExp(r'^.+@[a-zA-Z]+\.{1}[a-zA-Z]+(\.{0,1}[a-zA-Z]+)$')
                      .hasMatch(_pdfTextWebLink!.url);

              //the assumption here is that this is a mail or https url, why's that?
             // why is any of this necessary?
              final String scheme = isMailID
                  ? !_pdfTextWebLink!.url.contains('mailto')
                      ? 'mailto'
                      : ''
                  : (!_pdfTextWebLink!.url.contains('https') &&
                          !_pdfTextWebLink!.url.contains('http'))
                      ? 'https'
                      : '';

              final Uri url = !_pdfTextWebLink!.url.contains(scheme)
                  ? scheme.contains('mailto')
                      ? Uri(scheme: scheme, path: _pdfTextWebLink!.url)
                      : Uri(scheme: scheme, host: _pdfTextWebLink!.url) //<--- this breaks, why is this even necessary.
                  : Uri.parse(_pdfTextWebLink!.url);
              _showHyperLinkDialog(url);
              markNeedsPaint();
              break;

On which target platforms have you observed this bug?

Android, iOS, Web, Web (Android browser), Web (iOS browser), Windows, macOS, Linux

Flutter Doctor output

N/A

jonl-percsolutions-com commented 1 day ago

Also to clarify, this issue appears in 27.2.2 still.