XMonad.Actions.Search: Issue with escaped URL

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

XMonad.Actions.Search: Issue with escaped URL

Christian Heinrich
Hi everyone,

I've started to use XMonad.Actions.Search and I'm trying to define my own SearchEngine as follows:

> searchFunc :: String -> String
> searchFunc s = "https://de.pons.com/übersetzung/französisch-deutsch/" ++ (escape s)
> pons = searchEngineF "pons" searchFunc

The german umlauts ü and ö are actually part of the URL. According to the documentation,
searchEngineF should not handle any escaping (unlike searchEngine), but the URL that is opened for "a" is

https://de.pons.com/%C3%83%C2%BCbersetzung/franz%C3%83%C2%B6sisch-deutsch/a

I can't find what I'm doing wrong even when looking at the source.

Could anyone point out to me how to open that URL without escaping anything? I'm just surprised that
the base-URL is escaped as well, and not just the argument. I'm pretty new to Haskell and would be
grateful for any hint.

Thanks!

Christian

_______________________________________________
xmonad mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/xmonad

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: XMonad.Actions.Search: Issue with escaped URL

Brandon Allbery
Strictly speaking that's an HTTP protocol violation, so it may be
being enforced somewhere in the network-uri package or an HTTP package
over it but under xmonad. (The common usage of ~ is also a violation,
which leads to %7E escapes.)

On 6/12/20, Christian Heinrich <[hidden email]> wrote:

> Hi everyone,
>
> I've started to use XMonad.Actions.Search and I'm trying to define my own
> SearchEngine as follows:
>
>> searchFunc :: String -> String
>> searchFunc s = "https://de.pons.com/übersetzung/französisch-deutsch/" ++
>> (escape s)
>> pons = searchEngineF "pons" searchFunc
>
> The german umlauts ü and ö are actually part of the URL. According to the
> documentation,
> searchEngineF should not handle any escaping (unlike searchEngine), but the
> URL that is opened for "a" is
>
> https://de.pons.com/%C3%83%C2%BCbersetzung/franz%C3%83%C2%B6sisch-deutsch/a
>
> I can't find what I'm doing wrong even when looking at the source.
>
> Could anyone point out to me how to open that URL without escaping anything?
> I'm just surprised that
> the base-URL is escaped as well, and not just the argument. I'm pretty new
> to Haskell and would be
> grateful for any hint.
>
> Thanks!
>
> Christian
>


--
brandon s allbery kf8nh
[hidden email]
_______________________________________________
xmonad mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/xmonad
Reply | Threaded
Open this post in threaded view
|

Re: XMonad.Actions.Search: Issue with escaped URL

Platon Pronko
In reply to this post by Christian Heinrich
Hi!

The issue is that search/promptSearch use safeSpawn internally, and safeSpawn does not deal with non-ASCII characters correctly (see https://mail.haskell.org/pipermail/xmonad/2020-April/015370.html and https://mail.haskell.org/pipermail/xmonad/2020-April/015371.html).

You can work around that, but since the call stack is slightly deep you will need quite a lot of code. Here's the snippet I that I tested on my machine, seems to work correctly:

safeSpawnUnicode :: MonadIO m => FilePath -> [String] -> m ()
safeSpawnUnicode prog args = io $ void $ forkProcess $ do
   uninstallSignalHandlers
   _ <- createSession
   executeFile prog True args Nothing

ponsSearchEngine = searchEngineF "pons" (\s -> "https://de.pons.com/übersetzung/französisch-deutsch/" ++ (escape s))

-- copied from XMonad.Actions.Search because it does not exort Search constructor
data SearchCopy = SearchCopy Name
instance XPrompt SearchCopy where
     showXPrompt (SearchCopy name) = "SearchCopy [" ++ name ++ "]: "
     nextCompletion _ = getNextCompletion
     commandToComplete _ c = c

promptSearchUnicode :: XPConfig -> SearchEngine -> X ()
promptSearchUnicode config (SearchEngine name site) =
     mkXPrompt (SearchCopy name) config (historyCompletionP ("SearchCopy [" `isPrefixOf`)) (\query -> safeSpawnUnicode "firefox" [site query])

showSearchPrompt = promptSearchUnicode myXPConfig ponsSearchEngine

Best regards,
Platon Pronko

On 2020-06-12 15:59, Christian Heinrich wrote:

> Hi everyone,
>
> I've started to use XMonad.Actions.Search and I'm trying to define my own SearchEngine as follows:
>
>> searchFunc :: String -> String
>> searchFunc s = "https://de.pons.com/übersetzung/französisch-deutsch/" ++ (escape s)
>> pons = searchEngineF "pons" searchFunc
>
> The german umlauts ü and ö are actually part of the URL. According to the documentation,
> searchEngineF should not handle any escaping (unlike searchEngine), but the URL that is opened for "a" is
>
> https://de.pons.com/%C3%83%C2%BCbersetzung/franz%C3%83%C2%B6sisch-deutsch/a
>
> I can't find what I'm doing wrong even when looking at the source.
>
> Could anyone point out to me how to open that URL without escaping anything? I'm just surprised that
> the base-URL is escaped as well, and not just the argument. I'm pretty new to Haskell and would be
> grateful for any hint.
>
> Thanks!
>
> Christian
>
>
> _______________________________________________
> xmonad mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/xmonad
>
_______________________________________________
xmonad mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/xmonad