andy-portmen / native-client

Native Messaging component for Windows, Linux, and Mac OS that is written in NodeJS.
https://add0n.com/open-in.html
Mozilla Public License 2.0
727 stars 474 forks source link

URL problem #24

Closed undefo closed 7 years ago

undefo commented 7 years ago

Hello, Andy! Thanks for nice extension in first. I have 1 big problem: If URL looks like "https://translate.google.com/?hl=en&tab=TT#en/ru/sample" and I use the "[HREF]" argument then the external app get incomplete URL like "https://translate.google.com/?hl=en". The argument is truncated by the "&".

andy-portmen commented 7 years ago

Hi,

Which one of my extensions causes this issue? I checked "Open in Firefox" for instance and it seems to work fine.

undefo commented 7 years ago

Oh, sorry. I use "External Application Button 0.1.7" for Google Chrome

andy-portmen commented 7 years ago

I am not able to reproduce. Check this cast

undefo commented 7 years ago

It was my mistake. I tried to run powershell script and argument was truncated by ampersand. In order to pass an argument with an ampersand, you need to enclose it in single and double quotes. For example "'[HREF]'". I'm sorry for the time wasted.

andy-portmen commented 7 years ago

This is a useful hint. Can you add a comment on the review section of the FAQs page linking to this page? http://add0n.com/external-application-button.html

cyberpunkbln commented 7 years ago

@undefo Hi, can you short explain, how you run the powershell scripts? Directly with execution policy change or in another way? Thx.

undefo commented 7 years ago

@cyberpunkbln Hi! With execution policy change of course. I don't have root trusted certificate :)

My method of passing the correct URL and launching the script is not simple. I execute vbs with arguments that exec ps1 with arguments. LOL

cyberpunkbln commented 7 years ago

@undefo

Oh Okay:) i try do do it with -executionpolicy bypass -File or -Command inside an cmd-batch and as an powershell.exe in the Options directly, but all fails. cmd-batch don't take ampersand without ^ and powershell.exe starting causes nodejs failure or don't start.

Vbs crazy way :), is it possible to use vbs for -executionpolicy bypass -File?

But is a good way to use another script-interpreter for that.

undefo commented 7 years ago

I started using vbs just because of ^. It's my vbs for runnig ps:

Set objArgs = WScript.Arguments
if objArgs.count <> 0 then
    Set objShell = CreateObject("Wscript.shell")
    objShell.run("powershell -Command d:\scripts\start.ps1 " & URLEncode(objArgs(0),true))
end if

Function URLEncode(StringToEncode, UsePlusRatherThanHexForSpace)
  Dim TempAns, CurChr, iChar
  CurChr = 1
  Do Until CurChr - 1 = Len(StringToEncode)
    iChar = Asc(Mid(StringToEncode, CurChr, 1))
    If (iChar > 47 And iChar < 58)  Or (iChar > 64 And iChar < 91) Or (iChar > 96 And iChar < 123) Then
      TempAns = TempAns & Mid(StringToEncode, CurChr, 1)
    ElseIf iChar = 32 Then
      If UsePlusRatherThanHexForSpace Then
        TempAns = TempAns & "+"
      Else
        TempAns = TempAns & "%" & Hex(32)
      End If
    Else
      TempAns = TempAns & "%" & Right("00" & Hex(Asc(Mid(StringToEncode, CurChr, 1))), 2)
    End If
    CurChr = CurChr + 1
  Loop
  URLEncode = TempAns
End Function

It's External Button settings: Executable name: wscript Arguments: D:/scripts/wrapper.vbs [HREF]

cyberpunkbln commented 7 years ago

Hi, thx for that script, i will try it.