diff --git a/locale/de/Notepad4.rc b/locale/de/Notepad4.rc index fea38217d1..50f3780726 100644 --- a/locale/de/Notepad4.rc +++ b/locale/de/Notepad4.rc @@ -759,6 +759,7 @@ BEGIN MENUITEM "&Malayalam nach Latein", IDM_EDIT_MAP_MALAYALAM_LATIN END MENUITEM "&URL Codierung\tStrg+Shift+E", IDM_EDIT_URLENCODE + MENUITEM "URL Component Encode", IDM_EDIT_URLCOMPONENTENCODE MENUITEM "UR&L Decodierung\tStrg+Shift+R", IDM_EDIT_URLDECODE END POPUP "&Hilfe" diff --git a/locale/fr/Notepad4.rc b/locale/fr/Notepad4.rc index ef8982f890..2c55afdf18 100644 --- a/locale/fr/Notepad4.rc +++ b/locale/fr/Notepad4.rc @@ -759,6 +759,7 @@ BEGIN MENUITEM "&Malayalam à Latin", IDM_EDIT_MAP_MALAYALAM_LATIN END MENUITEM "Encodage des &URL\tCtrl+Shift+E", IDM_EDIT_URLENCODE + MENUITEM "URL Component Encode", IDM_EDIT_URLCOMPONENTENCODE MENUITEM "Décodage des UR&L\tCtrl+Shift+R", IDM_EDIT_URLDECODE END POPUP "Aide" diff --git a/locale/it/Notepad4.rc b/locale/it/Notepad4.rc index b5dfc77470..828998d0df 100644 --- a/locale/it/Notepad4.rc +++ b/locale/it/Notepad4.rc @@ -759,6 +759,7 @@ BEGIN MENUITEM "&Malayalam a Latino", IDM_EDIT_MAP_MALAYALAM_LATIN END MENUITEM "Codifica &URL\tCtrl+Shift+E", IDM_EDIT_URLENCODE + MENUITEM "URL Component Encode", IDM_EDIT_URLCOMPONENTENCODE MENUITEM "Decodifica UR&L\tCtrl+Shift+R", IDM_EDIT_URLDECODE END POPUP "&Aiuto" diff --git a/locale/ja/Notepad4.rc b/locale/ja/Notepad4.rc index 0a53eefe0a..71d28e9362 100644 --- a/locale/ja/Notepad4.rc +++ b/locale/ja/Notepad4.rc @@ -759,6 +759,7 @@ BEGIN MENUITEM "マラヤーラム語を(&M)", IDM_EDIT_MAP_MALAYALAM_LATIN END MENUITEM "URLエンコード(&U)\tCtrl+Shift+E", IDM_EDIT_URLENCODE + MENUITEM "URL Component Encode", IDM_EDIT_URLCOMPONENTENCODE MENUITEM "URLデコード(&L)\tCtrl+Shift+R", IDM_EDIT_URLDECODE END POPUP "ヘルプ(&H)" diff --git a/locale/ko/Notepad4.rc b/locale/ko/Notepad4.rc index bdfe795f63..143c958678 100644 --- a/locale/ko/Notepad4.rc +++ b/locale/ko/Notepad4.rc @@ -759,6 +759,7 @@ BEGIN MENUITEM "말라얄람 문자를 라틴 문자로(&M)", IDM_EDIT_MAP_MALAYALAM_LATIN END MENUITEM "URL 인코드(&U)\tCtrl+Shift+E", IDM_EDIT_URLENCODE + MENUITEM "URL Component Encode", IDM_EDIT_URLCOMPONENTENCODE MENUITEM "URL 디코드(&L)\tCtrl+Shift+R", IDM_EDIT_URLDECODE END POPUP "도움말(&H)" diff --git a/locale/pt-BR/Notepad4.rc b/locale/pt-BR/Notepad4.rc index a4ed5d171e..77979af9e3 100644 --- a/locale/pt-BR/Notepad4.rc +++ b/locale/pt-BR/Notepad4.rc @@ -759,6 +759,7 @@ BEGIN MENUITEM "&Malayalam to Latin", IDM_EDIT_MAP_MALAYALAM_LATIN END MENUITEM "&URL Encode\tCtrl+Shift+E", IDM_EDIT_URLENCODE + MENUITEM "URL Component Encode", IDM_EDIT_URLCOMPONENTENCODE MENUITEM "UR&L Decode\tCtrl+Shift+R", IDM_EDIT_URLDECODE END POPUP "&Help" diff --git a/locale/ru/Notepad4.rc b/locale/ru/Notepad4.rc index d53feebc59..2d98a5893b 100644 --- a/locale/ru/Notepad4.rc +++ b/locale/ru/Notepad4.rc @@ -760,6 +760,7 @@ BEGIN MENUITEM "Из &малаялам в латинский", IDM_EDIT_MAP_MALAYALAM_LATIN END MENUITEM "Закодировать в &URL\tCtrl+Shift+E", IDM_EDIT_URLENCODE + MENUITEM "URL Component Encode", IDM_EDIT_URLCOMPONENTENCODE MENUITEM "Декодировать из UR&L\tCtrl+Shift+R", IDM_EDIT_URLDECODE END POPUP "&Справка" diff --git a/locale/zh-Hans/Notepad4.rc b/locale/zh-Hans/Notepad4.rc index ece135ac5a..ed8040c7bb 100644 --- a/locale/zh-Hans/Notepad4.rc +++ b/locale/zh-Hans/Notepad4.rc @@ -759,6 +759,7 @@ BEGIN MENUITEM "马拉雅拉姆语转拉丁语(&M)",IDM_EDIT_MAP_MALAYALAM_LATIN END MENUITEM "URL 编码(&U)\tCtrl+Shift+E", IDM_EDIT_URLENCODE + MENUITEM "URL 组件编码", IDM_EDIT_URLCOMPONENTENCODE MENUITEM "URL 解码(&L)\tCtrl+Shift+R", IDM_EDIT_URLDECODE END POPUP "帮助(&H)" diff --git a/locale/zh-Hant/Notepad4.rc b/locale/zh-Hant/Notepad4.rc index 223f31202d..d659193d0e 100644 --- a/locale/zh-Hant/Notepad4.rc +++ b/locale/zh-Hant/Notepad4.rc @@ -759,6 +759,7 @@ BEGIN MENUITEM "馬拉雅拉姆語轉拉丁語(&M)", IDM_EDIT_MAP_MALAYALAM_LATIN END MENUITEM "URL 編碼(&U)\tCtrl+Shift+E", IDM_EDIT_URLENCODE + MENUITEM "URL 元件編碼", IDM_EDIT_URLCOMPONENTENCODE MENUITEM "URL 解碼(&L)\tCtrl+Shift+R", IDM_EDIT_URLDECODE END POPUP "說明(&H)" diff --git a/src/Edit.cpp b/src/Edit.cpp index ef3ad5ced0..981039eada 100644 --- a/src/Edit.cpp +++ b/src/Edit.cpp @@ -1683,12 +1683,15 @@ void EditMapTextCase(int menu) noexcept { #ifndef URL_UNESCAPE_AS_UTF8 // NTDDI_VERSION >= NTDDI_WIN8 #define URL_UNESCAPE_AS_UTF8 URL_ESCAPE_AS_UTF8 #endif +#ifndef URL_ESCAPE_ASCII_URI_COMPONENT // NTDDI_VERSION >= NTDDI_WIN8 +#define URL_ESCAPE_ASCII_URI_COMPONENT 0x00080000 +#endif //============================================================================= // // EditURLEncode() // -LPWSTR EditURLEncodeSelection(int *pcchEscaped) noexcept { +LPWSTR EditURLEncodeSelection(int *pcchEscaped, bool component) noexcept { *pcchEscaped = 0; const Sci_Position iSelCount = SciCall_GetSelTextLength(); if (iSelCount == 0) { @@ -1713,18 +1716,15 @@ LPWSTR EditURLEncodeSelection(int *pcchEscaped) noexcept { LPWSTR pszEscapedW = static_cast(NP2HeapAlloc(NP2HeapSize(pszTextW) * kMaxMultiByteCount * 3)); // '&', H1, H0 DWORD cchEscapedW = static_cast(NP2HeapSize(pszEscapedW) / sizeof(WCHAR)); - UrlEscape(pszTextW, pszEscapedW, &cchEscapedW, URL_ESCAPE_AS_UTF8); - if (!IsWin7AndAbove()) { - // TODO: encode some URL parts as UTF-8 then percent escape these UTF-8 bytes. - //ParseURL(pszEscapedW, &ppu); - } + const DWORD flags = component ? (URL_ESCAPE_AS_UTF8 | URL_ESCAPE_ASCII_URI_COMPONENT | URL_ESCAPE_SEGMENT_ONLY) : URL_ESCAPE_AS_UTF8; + UrlEscape(pszTextW, pszEscapedW, &cchEscapedW, flags); NP2HeapFree(pszTextW); *pcchEscaped = cchEscapedW; return pszEscapedW; } -void EditURLEncode() noexcept { +void EditURLEncode(bool component) noexcept { const Sci_Position iSelCount = SciCall_GetSelTextLength(); if (iSelCount == 0) { return; @@ -1735,7 +1735,7 @@ void EditURLEncode() noexcept { } int cchEscapedW; - LPWSTR pszEscapedW = EditURLEncodeSelection(&cchEscapedW); + LPWSTR pszEscapedW = EditURLEncodeSelection(&cchEscapedW, component); if (pszEscapedW == nullptr) { return; } @@ -6893,7 +6893,7 @@ void EditSelectionAction(int action) noexcept { } int cchEscapedW; - LPWSTR pszEscapedW = EditURLEncodeSelection(&cchEscapedW); + LPWSTR pszEscapedW = EditURLEncodeSelection(&cchEscapedW, false); if (pszEscapedW == nullptr) { return; } diff --git a/src/Edit.h b/src/Edit.h index b0e1bdbc68..2f2d0baa70 100644 --- a/src/Edit.h +++ b/src/Edit.h @@ -146,7 +146,7 @@ bool EditSaveFile(HWND hwnd, LPCWSTR pszFile, int saveFlag, EditFileIOStatus &st void EditReplaceMainSelection(Sci_Position cchText, LPCSTR pszText) noexcept; void EditMapTextCase(int menu) noexcept; -void EditURLEncode() noexcept; +void EditURLEncode(bool component) noexcept; void EditURLDecode() noexcept; void EditEscapeCChars(HWND hwnd) noexcept; void EditUnescapeCChars(HWND hwnd) noexcept; diff --git a/src/Notepad4.cpp b/src/Notepad4.cpp index 5aba9017b0..1da7ca079a 100644 --- a/src/Notepad4.cpp +++ b/src/Notepad4.cpp @@ -2466,6 +2466,7 @@ void MsgInitMenu(HWND hwnd, WPARAM wParam, LPARAM lParam) noexcept { IDM_EDIT_SPLITLINES, IDM_EDIT_TITLECASE, IDM_EDIT_UNESCAPECCHARS, + IDM_EDIT_URLCOMPONENTENCODE, IDM_EDIT_URLDECODE, IDM_EDIT_URLENCODE, IDM_EDIT_XHTML_ESCAPE_CHAR, @@ -3564,15 +3565,12 @@ LRESULT MsgCommand(HWND hwnd, WPARAM wParam, LPARAM lParam) { break; case IDM_EDIT_URLENCODE: - BeginWaitCursor(); - EditURLEncode(); - EndWaitCursor(); + case IDM_EDIT_URLCOMPONENTENCODE: + EditURLEncode(LOWORD(wParam) == IDM_EDIT_URLCOMPONENTENCODE); break; case IDM_EDIT_URLDECODE: - BeginWaitCursor(); EditURLDecode(); - EndWaitCursor(); break; case IDM_EDIT_ESCAPECCHARS: diff --git a/src/Notepad4.rc b/src/Notepad4.rc index a1e6ff1922..9446cc9fe9 100644 --- a/src/Notepad4.rc +++ b/src/Notepad4.rc @@ -758,6 +758,7 @@ BEGIN MENUITEM "&Malayalam to Latin", IDM_EDIT_MAP_MALAYALAM_LATIN END MENUITEM "&URL Encode\tCtrl+Shift+E", IDM_EDIT_URLENCODE + MENUITEM "URL Component Encode", IDM_EDIT_URLCOMPONENTENCODE MENUITEM "UR&L Decode\tCtrl+Shift+R", IDM_EDIT_URLDECODE END POPUP "&Help" diff --git a/src/resource.h b/src/resource.h index 374b00a631..22ac26dbca 100644 --- a/src/resource.h +++ b/src/resource.h @@ -574,7 +574,7 @@ #define IDM_EDIT_CONVERTLOWERCASE 40340 // Ctrl+U #define IDM_EDIT_MERGEDUPLICATELINE 40341 #define IDM_EDIT_REMOVEDUPLICATELINE 40342 - +#define IDM_EDIT_URLDECODE 40343 // Ctrl+Shift+R #define IDM_EDIT_CONVERTTABS 40344 // Ctrl+Shift+S #define IDM_EDIT_CONVERTSPACES 40345 // Ctrl+Shift+T #define IDM_EDIT_CONVERTTABS2 40346 // Ctrl+Alt+S @@ -588,7 +588,7 @@ #define IDM_EDIT_LINECOMMENT 40354 // Ctrl+/ #define IDM_EDIT_STREAMCOMMENT 40355 // Ctrl+Q #define IDM_EDIT_URLENCODE 40356 // Ctrl+Shift+E -#define IDM_EDIT_URLDECODE 40357 // Ctrl+Shift+R +#define IDM_EDIT_URLCOMPONENTENCODE 40357 #define IDM_EDIT_ESCAPECCHARS 40358 // Ctrl+Alt+E #define IDM_EDIT_UNESCAPECCHARS 40359 // Ctrl+Alt+R #define IDM_EDIT_CHAR2HEX 40360 // Ctrl+Alt+X