[intellij-sh] IDEA-230393 Add encode of explainshell url

GitOrigin-RevId: 4d1e65034f7afd4568485ee399bdd0545f3c2cdb
This commit is contained in:
Mikhail Mazurkevich
2020-01-10 09:35:05 +00:00
committed by intellij-monorepo-bot
parent 7dd6566f8d
commit 282fb30194
@@ -3,12 +3,14 @@ package com.intellij.sh;
import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
import com.intellij.ide.BrowserUtil;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Caret;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.SelectionModel;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Pass;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.CharsetToolkit;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.impl.source.tree.LeafPsiElement;
@@ -25,12 +27,15 @@ import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class ShExplainShellIntention extends BaseIntentionAction {
private final static Logger LOG = Logger.getInstance(ShExplainShellIntention.class);
@NonNls private static final String FEATURE_ACTION_ID = "ExplainShellUsed";
@NotNull
@@ -107,6 +112,13 @@ public class ShExplainShellIntention extends BaseIntentionAction {
}
private static void explain(@NotNull String text) {
BrowserUtil.browse("https://explainshell.com/explain?cmd=" + text);
String encodedText = text;
try {
encodedText = URLEncoder.encode(text, CharsetToolkit.UTF8);
}
catch (UnsupportedEncodingException e) {
LOG.warn("Couldn't encode " + text + " for explainshell URL", e);
}
BrowserUtil.browse("https://explainshell.com/explain?cmd=" + encodedText);
}
}