Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Threw a bug when I tried to make a link out of '-->' (User error?) #1794

Closed
tscahill opened this issue Dec 11, 2021 · 5 comments
Closed

Threw a bug when I tried to make a link out of '-->' (User error?) #1794

tscahill opened this issue Dec 11, 2021 · 5 comments

Comments

@tscahill
Copy link

To Reproduce
Steps to reproduce the behavior:

  1. Type "-->". Zim converts this into a right-pointing arrow. (Very nice!)
  2. Press Ctrl-L. Voila!
    As the error says: "raise ValueError('Not a valid page name: %s (was: %s)' % (newname, name))
    ValueError: Not a valid page name: (was: →)"

Environment (please complete the following information):

  • Version [e.g. 0.74.0] -- This is running as source (launched with ./zim.py)
  • OS: [e.g. linux/windows/mac os]
  • Language: especially for errors that might relate to character encoding or other locale specific issues

Traceback

`This is zim 0.74.3
Platform: posix (Manjaro 21.1)
Locale: en_CA UTF-8
FS encoding: utf-8
Python: (3, 9, 7, 'final', 0)
PyGObject: (3, 42, 0)

======= Traceback =======
File "/home/tim/Downloads/Linux/Zim/zim-desktop-wiki-master/zim/actions.py", line 159, in _on_activate
self.call()
File "/home/tim/Downloads/Linux/Zim/zim-desktop-wiki-master/zim/actions.py", line 130, in call
return self._action.func(self._instance, *args, **kwargs)
File "/home/tim/Downloads/Linux/Zim/zim-desktop-wiki-master/zim/gui/pageview/init.py", line 7144, in insert_link
InsertLinkDialog(self, self).run()
File "/home/tim/Downloads/Linux/Zim/zim-desktop-wiki-master/zim/gui/pageview/init.py", line 8068, in init
self._text_for_link = self._link_to_text(href)
File "/home/tim/Downloads/Linux/Zim/zim-desktop-wiki-master/zim/gui/pageview/init.py", line 8122, in _link_to_text
parts = HRef.new_from_wiki_link(link).parts()
File "/home/tim/Downloads/Linux/Zim/zim-desktop-wiki-master/zim/notebook/page.py", line 360, in new_from_wiki_link
names = Path.makeValidPageName(href.lstrip('+')) if href else ""
File "/home/tim/Downloads/Linux/Zim/zim-desktop-wiki-master/zim/notebook/page.py", line 157, in makeValidPageName
raise ValueError('Not a valid page name: %s (was: %s)' % (newname, name))
ValueError: Not a valid page name: (was: →)`

@introt
Copy link
Collaborator

introt commented Dec 13, 2021

Can confirm, not a user error; can be reproduced with any string that "reduces to an empty string" by makeValidPageName, eg. ) or ??.

@introt
Copy link
Collaborator

introt commented Dec 13, 2021

While the fix makes _link_to_text return an empty string, the dialog gets filled with the original string, making it possible to create invalid links that open the bug dialog when activated:

======= Traceback =======
  File "/home/introt/repos/zim-desktop-wiki/zim/gui/pageview/__init__.py", line 6513, in do_activate_link
    self._do_activate_link(link, hints)
  File "/home/introt/repos/zim-desktop-wiki/zim/gui/pageview/__init__.py", line 6522, in _do_activate_link
    href = HRef.new_from_wiki_link(link)
  File "/home/introt/repos/zim-desktop-wiki/zim/notebook/page.py", line 359, in new_from_wiki_link
    names = Path.makeValidPageName(href.lstrip('+')) if href else ""
  File "/home/introt/repos/zim-desktop-wiki/zim/notebook/page.py", line 156, in makeValidPageName
    raise ValueError('Not a valid page name: %s (was: %s)' % (newname, name))
ValueError: Not a valid page name:  (was: →)

Since one can create these invalid links via other means, eg. editing page source, I'd consider that a separate issue whose fix would be showing an error dialog like the one shown with links to non-existing anchors.

@introt
Copy link
Collaborator

introt commented Dec 13, 2021

Haven't looked into zim.errors.exception_handler, but here's a quick mock of a patch

diff --git a/zim/gui/pageview/__init__.py b/zim/gui/pageview/__init__.py
index 83c63c42..57a67568 100644
--- a/zim/gui/pageview/__init__.py
+++ b/zim/gui/pageview/__init__.py
@@ -6511,6 +6511,8 @@ class PageView(GSignalEmitterMixin, Gtk.VBox):
        def do_activate_link(self, link, hints):
                try:
                        self._do_activate_link(link, hints)
+               except ValueError:
+                       ErrorDialog(self, _('Invalid link: "%s"') % link).run() # T: error when invalid link clicked
                except:
                        zim.errors.exception_handler(
                                'Exception during activate-link(%r)' % ((link, hints),))

image

@introt
Copy link
Collaborator

introt commented Dec 13, 2021

Could also switch out zim.errors.exception_handler with show_error...

image

@introt
Copy link
Collaborator

introt commented Feb 20, 2022

Fixed by 458688c (the fix for #1932), though it does result in the aforementioned ValueError: Not a valid page name: (was: →) on click.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants