plugin.video.iptv.recorder icon indicating copy to clipboard operation
plugin.video.iptv.recorder copied to clipboard

non-ascii characters in search input

Open mmiesiak opened this issue 6 years ago • 3 comments

When you search for title/category/plot with non-ascii characters, next time you open the search dialog it crashes with following error:

2019-03-13 22:28:57.889 T:3509703536 WARNING: Previous line repeats 1 times.                                                     
2019-03-13 22:28:57.889 T:3509703536  NOTICE: [xbmcswift2] Request for "/search_title_dialog" matches rule for function "search_title_dialog"              
2019-03-13 22:28:57.900 T:3509703536   ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--   
                                             - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!                                                     
                                            Error Type: <type 'exceptions.KeyError'>                                                                         
                                            Error Contents: u'\u0142'                                                                            
                                            Traceback (most recent call last):                                                                   
                                              File "/storage/.kodi/addons/plugin.video.iptv.recorder/main.py", line 3162, in <module>                      
                                                plugin.run()                                                                                     
                                              File "/storage/.kodi/addons/script.module.xbmcswift2/lib/xbmcswift2/plugin.py", line 332, in run
                                                items = self._dispatch(self.request.path)                                                     
                                              File "/storage/.kodi/addons/script.module.xbmcswift2/lib/xbmcswift2/plugin.py", line 306, in _dispatch
                                                listitems = view_func(**items)                                                                      
                                              File "/storage/.kodi/addons/plugin.video.iptv.recorder/main.py", line 1398, in search_title_dialog    
                                                context_items.append((_("Delete Search"), 'XBMC.RunPlugin(%s)' % (plugin.url_for(delete_search_title, title=search))))
                                              File "/storage/.kodi/addons/script.module.xbmcswift2/lib/xbmcswift2/plugin.py", line 295, in url_for                    
                                                pathqs = rule.make_path_qs(items)                                                                                     
                                              File "/storage/.kodi/addons/script.module.xbmcswift2/lib/xbmcswift2/urls.py", line 160, in make_path_qs                 
                                                path = self._make_path(url_items)                                                                                     
                                              File "/storage/.kodi/addons/script.module.xbmcswift2/lib/xbmcswift2/urls.py", line 110, in _make_path                   
                                                items[key] = quote_plus(val)                                                                                          
                                              File "/usr/lib/python2.7/urllib.py", line 1303, in quote_plus                                          
                                              File "/usr/lib/python2.7/urllib.py", line 1298, in quote                                               
                                            KeyError: u'\u0142'                                                                                      
                                            -->End of Python script error report<--                                                                        
2019-03-13 22:28:58.086 T:3492918128   ERROR: GetDirectory - Error getting plugin://plugin.video.iptv.recorder/search_title_dialog                 
2019-03-13 22:28:58.091 T:4093035296   ERROR: CGUIMediaWindow::GetDirectory(plugin://plugin.video.iptv.recorder/search_title_dialog) failed

It seems the problem is with encoding when it tries to get search history and add it to the list. To resolve that the search items must be first UTF-8 encoded.

Example:

    for search in searches:                                         
        context_items = []                                          
        log(search)                                                   
        context_items.append((_("Delete Search"), 'XBMC.RunPlugin(%s)' % (plugin.url_for(delete_search_title, title=search.encode("utf8")))))
        items.append({                                                                                                                       
            "label": search,                                                                                                                 
            "path": plugin.url_for('search_title', title=search.encode("utf8")),                                                             
            "thumbnail": get_icon_path('search'),                                                                                            
            'context_menu': context_items,                                                                                                   
            })                                                                                                                               
    return items 

I can prepare PR in next days if you want.

mmiesiak avatar Mar 14 '19 10:03 mmiesiak

Yes, please.

primaeval avatar Mar 14 '19 10:03 primaeval

You are too fast, I saw you already have fixed it. Thanks!

mmiesiak avatar Mar 15 '19 14:03 mmiesiak

Luckily I had a bit of spare time. If you get time to test some of the missing data variations that would be helpful.

primaeval avatar Mar 15 '19 14:03 primaeval