Skip to content

Commit

Permalink
fix(mr_create/issue_create): add encoding to title and change descrip…
Browse files Browse the repository at this point in the history
…tion encoding (profclems#871)

* fix(mr_create/issue_create): add encoding to title and change description encoding

- Prevent browsers from converting a space containing query to a search query
- Allow users to add symbols to their title and description
    - QueryEscape does not escape '+' which is converted to a space by the browser

* fix(issue_create) : remove unused repo parameter

* fix(issue_create/mr_create) : manually encode + to %2B

* fix(issue_create/mr_create) : prevent open from auto encoding characters

The tick on the URL makes `open` on a mac encode it, so already encoded data such as a %20 is encoded to %2520
Removing the utf8=`tick` prevents auto encoding and makes urls work as is allowing symbols to be used in title and description

Co-authored-by: Kartikay Shandil <kartikays@sahaj.ai>
  • Loading branch information
kartikay101 and kartikay-sahaj committed Nov 18, 2021
1 parent 0c20a97 commit a16cfe0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions commands/issue/create/issue_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ func previewIssue(opts *CreateOpts) error {
return err
}

openURL, err := generateIssueWebURL(opts, repo)
openURL, err := generateIssueWebURL(opts)
if err != nil {
return err
}
Expand All @@ -380,7 +380,7 @@ func previewIssue(opts *CreateOpts) error {
return utils.OpenInBrowser(openURL, browser)
}

func generateIssueWebURL(opts *CreateOpts, repo glrepo.Interface) (string, error) {
func generateIssueWebURL(opts *CreateOpts) (string, error) {
description := opts.Description

if len(opts.Labels) > 0 {
Expand Down Expand Up @@ -415,8 +415,8 @@ func generateIssueWebURL(opts *CreateOpts, repo glrepo.Interface) (string, error
}
u.Path += "/-/issues/new"
u.RawQuery = fmt.Sprintf(
"utf8=✓&issue[title]=%s&issue[description]=%s",
opts.Title,
url.QueryEscape(description))
"issue[title]=%s&issue[description]=%s",
strings.ReplaceAll(url.PathEscape(opts.Title), "+", "%2B"),
strings.ReplaceAll(url.PathEscape(description), "+", "%2B"))
return u.String(), nil
}
6 changes: 3 additions & 3 deletions commands/mr/create/mr_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -684,9 +684,9 @@ func generateMRCompareURL(opts *CreateOpts) (string, error) {
}
u.Path += "/-/merge_requests/new"
u.RawQuery = fmt.Sprintf(
"utf8=✓&merge_request[title]=%s&merge_request[description]=%s&merge_request[source_branch]=%s&merge_request[target_branch]=%s&merge_request[source_project_id]=%d&merge_request[target_project_id]=%d",
url.QueryEscape(opts.Title),
url.QueryEscape(description),
"merge_request[title]=%s&merge_request[description]=%s&merge_request[source_branch]=%s&merge_request[target_branch]=%s&merge_request[source_project_id]=%d&merge_request[target_project_id]=%d",
strings.ReplaceAll(url.PathEscape(opts.Title), "+", "%2B"),
strings.ReplaceAll(url.PathEscape(description), "+", "%2B"),
opts.SourceBranch,
opts.TargetBranch,
opts.SourceProject.ID,
Expand Down

0 comments on commit a16cfe0

Please sign in to comment.