Fix Git permalinks not being URL-escaped (#39895)
Closes #39875 Release Notes: - Fixed "open/copy permalink to line" paths not being URL-escaped Co-authored-by: Cole Miller <cole@zed.dev>
This commit is contained in:
co-authored by
Cole Miller
parent
2dfde55367
commit
c24f365b69
Generated
+2
@@ -6775,6 +6775,7 @@ dependencies = [
|
|||||||
"futures 0.3.31",
|
"futures 0.3.31",
|
||||||
"git2",
|
"git2",
|
||||||
"gpui",
|
"gpui",
|
||||||
|
"itertools 0.14.0",
|
||||||
"log",
|
"log",
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
"pretty_assertions",
|
"pretty_assertions",
|
||||||
@@ -6791,6 +6792,7 @@ dependencies = [
|
|||||||
"time",
|
"time",
|
||||||
"unindent",
|
"unindent",
|
||||||
"url",
|
"url",
|
||||||
|
"urlencoding",
|
||||||
"uuid",
|
"uuid",
|
||||||
"workspace-hack",
|
"workspace-hack",
|
||||||
"zed-collections",
|
"zed-collections",
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ derive_more.workspace = true
|
|||||||
git2.workspace = true
|
git2.workspace = true
|
||||||
gpui.workspace = true
|
gpui.workspace = true
|
||||||
http_client.workspace = true
|
http_client.workspace = true
|
||||||
|
itertools.workspace = true
|
||||||
log.workspace = true
|
log.workspace = true
|
||||||
parking_lot.workspace = true
|
parking_lot.workspace = true
|
||||||
regex.workspace = true
|
regex.workspace = true
|
||||||
@@ -36,6 +37,7 @@ text.workspace = true
|
|||||||
thiserror.workspace = true
|
thiserror.workspace = true
|
||||||
time.workspace = true
|
time.workspace = true
|
||||||
url.workspace = true
|
url.workspace = true
|
||||||
|
urlencoding.workspace = true
|
||||||
util.workspace = true
|
util.workspace = true
|
||||||
uuid.workspace = true
|
uuid.workspace = true
|
||||||
futures.workspace = true
|
futures.workspace = true
|
||||||
|
|||||||
@@ -5,9 +5,12 @@ use async_trait::async_trait;
|
|||||||
use derive_more::{Deref, DerefMut};
|
use derive_more::{Deref, DerefMut};
|
||||||
use gpui::{App, Global, SharedString};
|
use gpui::{App, Global, SharedString};
|
||||||
use http_client::HttpClient;
|
use http_client::HttpClient;
|
||||||
|
use itertools::Itertools;
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
use crate::repository::RepoPath;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||||
pub struct PullRequest {
|
pub struct PullRequest {
|
||||||
pub number: u32,
|
pub number: u32,
|
||||||
@@ -55,10 +58,21 @@ pub struct BuildCommitPermalinkParams<'a> {
|
|||||||
|
|
||||||
pub struct BuildPermalinkParams<'a> {
|
pub struct BuildPermalinkParams<'a> {
|
||||||
pub sha: &'a str,
|
pub sha: &'a str,
|
||||||
pub path: &'a str,
|
/// URL-escaped path using unescaped `/` as the directory separator.
|
||||||
|
pub path: String,
|
||||||
pub selection: Option<Range<u32>>,
|
pub selection: Option<Range<u32>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a> BuildPermalinkParams<'a> {
|
||||||
|
pub fn new(sha: &'a str, path: &RepoPath, selection: Option<Range<u32>>) -> Self {
|
||||||
|
Self {
|
||||||
|
sha,
|
||||||
|
path: path.components().map(urlencoding::encode).join("/"),
|
||||||
|
selection,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A Git hosting provider.
|
/// A Git hosting provider.
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait GitHostingProvider {
|
pub trait GitHostingProvider {
|
||||||
|
|||||||
@@ -30,3 +30,4 @@ workspace-hack.workspace = true
|
|||||||
indoc.workspace = true
|
indoc.workspace = true
|
||||||
serde_json.workspace = true
|
serde_json.workspace = true
|
||||||
pretty_assertions.workspace = true
|
pretty_assertions.workspace = true
|
||||||
|
git = { workspace = true, features = ["test-support"] }
|
||||||
|
|||||||
@@ -126,6 +126,7 @@ impl GitHostingProvider for Bitbucket {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use git::repository::repo_path;
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
@@ -182,11 +183,7 @@ mod tests {
|
|||||||
owner: "zed-industries".into(),
|
owner: "zed-industries".into(),
|
||||||
repo: "zed".into(),
|
repo: "zed".into(),
|
||||||
},
|
},
|
||||||
BuildPermalinkParams {
|
BuildPermalinkParams::new("f00b4r", &repo_path("main.rs"), None),
|
||||||
sha: "f00b4r",
|
|
||||||
path: "main.rs",
|
|
||||||
selection: None,
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
|
|
||||||
let expected_url = "https://bitbucket.org/zed-industries/zed/src/f00b4r/main.rs";
|
let expected_url = "https://bitbucket.org/zed-industries/zed/src/f00b4r/main.rs";
|
||||||
@@ -200,11 +197,7 @@ mod tests {
|
|||||||
owner: "zed-industries".into(),
|
owner: "zed-industries".into(),
|
||||||
repo: "zed".into(),
|
repo: "zed".into(),
|
||||||
},
|
},
|
||||||
BuildPermalinkParams {
|
BuildPermalinkParams::new("f00b4r", &repo_path("main.rs"), Some(6..6)),
|
||||||
sha: "f00b4r",
|
|
||||||
path: "main.rs",
|
|
||||||
selection: Some(6..6),
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
|
|
||||||
let expected_url = "https://bitbucket.org/zed-industries/zed/src/f00b4r/main.rs#lines-7";
|
let expected_url = "https://bitbucket.org/zed-industries/zed/src/f00b4r/main.rs#lines-7";
|
||||||
@@ -218,11 +211,7 @@ mod tests {
|
|||||||
owner: "zed-industries".into(),
|
owner: "zed-industries".into(),
|
||||||
repo: "zed".into(),
|
repo: "zed".into(),
|
||||||
},
|
},
|
||||||
BuildPermalinkParams {
|
BuildPermalinkParams::new("f00b4r", &repo_path("main.rs"), Some(23..47)),
|
||||||
sha: "f00b4r",
|
|
||||||
path: "main.rs",
|
|
||||||
selection: Some(23..47),
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
|
|
||||||
let expected_url =
|
let expected_url =
|
||||||
|
|||||||
@@ -191,6 +191,7 @@ impl GitHostingProvider for Chromium {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use git::repository::repo_path;
|
||||||
use indoc::indoc;
|
use indoc::indoc;
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
|
|
||||||
@@ -218,11 +219,11 @@ mod tests {
|
|||||||
owner: Arc::from(""),
|
owner: Arc::from(""),
|
||||||
repo: "chromium/src".into(),
|
repo: "chromium/src".into(),
|
||||||
},
|
},
|
||||||
BuildPermalinkParams {
|
BuildPermalinkParams::new(
|
||||||
sha: "fea5080b182fc92e3be0c01c5dece602fe70b588",
|
"fea5080b182fc92e3be0c01c5dece602fe70b588",
|
||||||
path: "ui/base/cursor/cursor.h",
|
&repo_path("ui/base/cursor/cursor.h"),
|
||||||
selection: None,
|
None,
|
||||||
},
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
let expected_url = "https://chromium.googlesource.com/chromium/src/+/fea5080b182fc92e3be0c01c5dece602fe70b588/ui/base/cursor/cursor.h";
|
let expected_url = "https://chromium.googlesource.com/chromium/src/+/fea5080b182fc92e3be0c01c5dece602fe70b588/ui/base/cursor/cursor.h";
|
||||||
@@ -236,11 +237,11 @@ mod tests {
|
|||||||
owner: Arc::from(""),
|
owner: Arc::from(""),
|
||||||
repo: "chromium/src".into(),
|
repo: "chromium/src".into(),
|
||||||
},
|
},
|
||||||
BuildPermalinkParams {
|
BuildPermalinkParams::new(
|
||||||
sha: "fea5080b182fc92e3be0c01c5dece602fe70b588",
|
"fea5080b182fc92e3be0c01c5dece602fe70b588",
|
||||||
path: "ui/base/cursor/cursor.h",
|
&repo_path("ui/base/cursor/cursor.h"),
|
||||||
selection: Some(18..18),
|
Some(18..18),
|
||||||
},
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
let expected_url = "https://chromium.googlesource.com/chromium/src/+/fea5080b182fc92e3be0c01c5dece602fe70b588/ui/base/cursor/cursor.h#19";
|
let expected_url = "https://chromium.googlesource.com/chromium/src/+/fea5080b182fc92e3be0c01c5dece602fe70b588/ui/base/cursor/cursor.h#19";
|
||||||
@@ -254,11 +255,11 @@ mod tests {
|
|||||||
owner: Arc::from(""),
|
owner: Arc::from(""),
|
||||||
repo: "chromium/src".into(),
|
repo: "chromium/src".into(),
|
||||||
},
|
},
|
||||||
BuildPermalinkParams {
|
BuildPermalinkParams::new(
|
||||||
sha: "fea5080b182fc92e3be0c01c5dece602fe70b588",
|
"fea5080b182fc92e3be0c01c5dece602fe70b588",
|
||||||
path: "ui/base/cursor/cursor.h",
|
&repo_path("ui/base/cursor/cursor.h"),
|
||||||
selection: Some(18..30),
|
Some(18..30),
|
||||||
},
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
let expected_url = "https://chromium.googlesource.com/chromium/src/+/fea5080b182fc92e3be0c01c5dece602fe70b588/ui/base/cursor/cursor.h#19";
|
let expected_url = "https://chromium.googlesource.com/chromium/src/+/fea5080b182fc92e3be0c01c5dece602fe70b588/ui/base/cursor/cursor.h#19";
|
||||||
|
|||||||
@@ -204,6 +204,7 @@ impl GitHostingProvider for Codeberg {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use git::repository::repo_path;
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
@@ -245,11 +246,11 @@ mod tests {
|
|||||||
owner: "zed-industries".into(),
|
owner: "zed-industries".into(),
|
||||||
repo: "zed".into(),
|
repo: "zed".into(),
|
||||||
},
|
},
|
||||||
BuildPermalinkParams {
|
BuildPermalinkParams::new(
|
||||||
sha: "faa6f979be417239b2e070dbbf6392b909224e0b",
|
"faa6f979be417239b2e070dbbf6392b909224e0b",
|
||||||
path: "crates/editor/src/git/permalink.rs",
|
&repo_path("crates/editor/src/git/permalink.rs"),
|
||||||
selection: None,
|
None,
|
||||||
},
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
let expected_url = "https://codeberg.org/zed-industries/zed/src/commit/faa6f979be417239b2e070dbbf6392b909224e0b/crates/editor/src/git/permalink.rs";
|
let expected_url = "https://codeberg.org/zed-industries/zed/src/commit/faa6f979be417239b2e070dbbf6392b909224e0b/crates/editor/src/git/permalink.rs";
|
||||||
@@ -263,11 +264,11 @@ mod tests {
|
|||||||
owner: "zed-industries".into(),
|
owner: "zed-industries".into(),
|
||||||
repo: "zed".into(),
|
repo: "zed".into(),
|
||||||
},
|
},
|
||||||
BuildPermalinkParams {
|
BuildPermalinkParams::new(
|
||||||
sha: "faa6f979be417239b2e070dbbf6392b909224e0b",
|
"faa6f979be417239b2e070dbbf6392b909224e0b",
|
||||||
path: "crates/editor/src/git/permalink.rs",
|
&repo_path("crates/editor/src/git/permalink.rs"),
|
||||||
selection: Some(6..6),
|
Some(6..6),
|
||||||
},
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
let expected_url = "https://codeberg.org/zed-industries/zed/src/commit/faa6f979be417239b2e070dbbf6392b909224e0b/crates/editor/src/git/permalink.rs#L7";
|
let expected_url = "https://codeberg.org/zed-industries/zed/src/commit/faa6f979be417239b2e070dbbf6392b909224e0b/crates/editor/src/git/permalink.rs#L7";
|
||||||
@@ -281,11 +282,11 @@ mod tests {
|
|||||||
owner: "zed-industries".into(),
|
owner: "zed-industries".into(),
|
||||||
repo: "zed".into(),
|
repo: "zed".into(),
|
||||||
},
|
},
|
||||||
BuildPermalinkParams {
|
BuildPermalinkParams::new(
|
||||||
sha: "faa6f979be417239b2e070dbbf6392b909224e0b",
|
"faa6f979be417239b2e070dbbf6392b909224e0b",
|
||||||
path: "crates/editor/src/git/permalink.rs",
|
&repo_path("crates/editor/src/git/permalink.rs"),
|
||||||
selection: Some(23..47),
|
Some(23..47),
|
||||||
},
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
let expected_url = "https://codeberg.org/zed-industries/zed/src/commit/faa6f979be417239b2e070dbbf6392b909224e0b/crates/editor/src/git/permalink.rs#L24-L48";
|
let expected_url = "https://codeberg.org/zed-industries/zed/src/commit/faa6f979be417239b2e070dbbf6392b909224e0b/crates/editor/src/git/permalink.rs#L24-L48";
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ impl GitHostingProvider for Gitee {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use git::repository::repo_path;
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
@@ -125,11 +126,11 @@ mod tests {
|
|||||||
owner: "zed-industries".into(),
|
owner: "zed-industries".into(),
|
||||||
repo: "zed".into(),
|
repo: "zed".into(),
|
||||||
},
|
},
|
||||||
BuildPermalinkParams {
|
BuildPermalinkParams::new(
|
||||||
sha: "e5fe811d7ad0fc26934edd76f891d20bdc3bb194",
|
"e5fe811d7ad0fc26934edd76f891d20bdc3bb194",
|
||||||
path: "crates/editor/src/git/permalink.rs",
|
&repo_path("crates/editor/src/git/permalink.rs"),
|
||||||
selection: None,
|
None,
|
||||||
},
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
let expected_url = "https://gitee.com/zed-industries/zed/blob/e5fe811d7ad0fc26934edd76f891d20bdc3bb194/crates/editor/src/git/permalink.rs";
|
let expected_url = "https://gitee.com/zed-industries/zed/blob/e5fe811d7ad0fc26934edd76f891d20bdc3bb194/crates/editor/src/git/permalink.rs";
|
||||||
@@ -143,11 +144,11 @@ mod tests {
|
|||||||
owner: "zed-industries".into(),
|
owner: "zed-industries".into(),
|
||||||
repo: "zed".into(),
|
repo: "zed".into(),
|
||||||
},
|
},
|
||||||
BuildPermalinkParams {
|
BuildPermalinkParams::new(
|
||||||
sha: "e5fe811d7ad0fc26934edd76f891d20bdc3bb194",
|
"e5fe811d7ad0fc26934edd76f891d20bdc3bb194",
|
||||||
path: "crates/editor/src/git/permalink.rs",
|
&repo_path("crates/editor/src/git/permalink.rs"),
|
||||||
selection: Some(6..6),
|
Some(6..6),
|
||||||
},
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
let expected_url = "https://gitee.com/zed-industries/zed/blob/e5fe811d7ad0fc26934edd76f891d20bdc3bb194/crates/editor/src/git/permalink.rs#L7";
|
let expected_url = "https://gitee.com/zed-industries/zed/blob/e5fe811d7ad0fc26934edd76f891d20bdc3bb194/crates/editor/src/git/permalink.rs#L7";
|
||||||
@@ -161,11 +162,11 @@ mod tests {
|
|||||||
owner: "zed-industries".into(),
|
owner: "zed-industries".into(),
|
||||||
repo: "zed".into(),
|
repo: "zed".into(),
|
||||||
},
|
},
|
||||||
BuildPermalinkParams {
|
BuildPermalinkParams::new(
|
||||||
sha: "e5fe811d7ad0fc26934edd76f891d20bdc3bb194",
|
"e5fe811d7ad0fc26934edd76f891d20bdc3bb194",
|
||||||
path: "crates/editor/src/git/permalink.rs",
|
&repo_path("crates/editor/src/git/permalink.rs"),
|
||||||
selection: Some(23..47),
|
Some(23..47),
|
||||||
},
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
let expected_url = "https://gitee.com/zed-industries/zed/blob/e5fe811d7ad0fc26934edd76f891d20bdc3bb194/crates/editor/src/git/permalink.rs#L24-48";
|
let expected_url = "https://gitee.com/zed-industries/zed/blob/e5fe811d7ad0fc26934edd76f891d20bdc3bb194/crates/editor/src/git/permalink.rs#L24-48";
|
||||||
|
|||||||
@@ -259,6 +259,7 @@ impl GitHostingProvider for Github {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use git::repository::repo_path;
|
||||||
use indoc::indoc;
|
use indoc::indoc;
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
|
|
||||||
@@ -400,11 +401,11 @@ mod tests {
|
|||||||
};
|
};
|
||||||
let permalink = Github::public_instance().build_permalink(
|
let permalink = Github::public_instance().build_permalink(
|
||||||
remote,
|
remote,
|
||||||
BuildPermalinkParams {
|
BuildPermalinkParams::new(
|
||||||
sha: "e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7",
|
"e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7",
|
||||||
path: "crates/editor/src/git/permalink.rs",
|
&repo_path("crates/editor/src/git/permalink.rs"),
|
||||||
selection: None,
|
None,
|
||||||
},
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
let expected_url = "https://github.com/zed-industries/zed/blob/e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7/crates/editor/src/git/permalink.rs";
|
let expected_url = "https://github.com/zed-industries/zed/blob/e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7/crates/editor/src/git/permalink.rs";
|
||||||
@@ -418,11 +419,11 @@ mod tests {
|
|||||||
owner: "zed-industries".into(),
|
owner: "zed-industries".into(),
|
||||||
repo: "zed".into(),
|
repo: "zed".into(),
|
||||||
},
|
},
|
||||||
BuildPermalinkParams {
|
BuildPermalinkParams::new(
|
||||||
sha: "b2efec9824c45fcc90c9a7eb107a50d1772a60aa",
|
"b2efec9824c45fcc90c9a7eb107a50d1772a60aa",
|
||||||
path: "crates/zed/src/main.rs",
|
&repo_path("crates/zed/src/main.rs"),
|
||||||
selection: None,
|
None,
|
||||||
},
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
let expected_url = "https://github.com/zed-industries/zed/blob/b2efec9824c45fcc90c9a7eb107a50d1772a60aa/crates/zed/src/main.rs";
|
let expected_url = "https://github.com/zed-industries/zed/blob/b2efec9824c45fcc90c9a7eb107a50d1772a60aa/crates/zed/src/main.rs";
|
||||||
@@ -436,11 +437,11 @@ mod tests {
|
|||||||
owner: "zed-industries".into(),
|
owner: "zed-industries".into(),
|
||||||
repo: "zed".into(),
|
repo: "zed".into(),
|
||||||
},
|
},
|
||||||
BuildPermalinkParams {
|
BuildPermalinkParams::new(
|
||||||
sha: "e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7",
|
"e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7",
|
||||||
path: "crates/editor/src/git/permalink.rs",
|
&repo_path("crates/editor/src/git/permalink.rs"),
|
||||||
selection: Some(6..6),
|
Some(6..6),
|
||||||
},
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
let expected_url = "https://github.com/zed-industries/zed/blob/e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7/crates/editor/src/git/permalink.rs#L7";
|
let expected_url = "https://github.com/zed-industries/zed/blob/e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7/crates/editor/src/git/permalink.rs#L7";
|
||||||
@@ -454,11 +455,11 @@ mod tests {
|
|||||||
owner: "zed-industries".into(),
|
owner: "zed-industries".into(),
|
||||||
repo: "zed".into(),
|
repo: "zed".into(),
|
||||||
},
|
},
|
||||||
BuildPermalinkParams {
|
BuildPermalinkParams::new(
|
||||||
sha: "e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7",
|
"e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7",
|
||||||
path: "crates/editor/src/git/permalink.rs",
|
&repo_path("crates/editor/src/git/permalink.rs"),
|
||||||
selection: Some(23..47),
|
Some(23..47),
|
||||||
},
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
let expected_url = "https://github.com/zed-industries/zed/blob/e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7/crates/editor/src/git/permalink.rs#L24-L48";
|
let expected_url = "https://github.com/zed-industries/zed/blob/e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7/crates/editor/src/git/permalink.rs#L24-L48";
|
||||||
@@ -506,4 +507,23 @@ mod tests {
|
|||||||
};
|
};
|
||||||
assert_eq!(github.extract_pull_request(&remote, message), None);
|
assert_eq!(github.extract_pull_request(&remote, message), None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Regression test for issue #39875
|
||||||
|
#[test]
|
||||||
|
fn test_git_permalink_url_escaping() {
|
||||||
|
let permalink = Github::public_instance().build_permalink(
|
||||||
|
ParsedGitRemote {
|
||||||
|
owner: "zed-industries".into(),
|
||||||
|
repo: "nonexistent".into(),
|
||||||
|
},
|
||||||
|
BuildPermalinkParams::new(
|
||||||
|
"3ef1539900037dd3601be7149b2b39ed6d0ce3db",
|
||||||
|
&repo_path("app/blog/[slug]/page.tsx"),
|
||||||
|
Some(7..7),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
let expected_url = "https://github.com/zed-industries/nonexistent/blob/3ef1539900037dd3601be7149b2b39ed6d0ce3db/app/blog/%5Bslug%5D/page.tsx#L8";
|
||||||
|
assert_eq!(permalink.to_string(), expected_url.to_string())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -126,6 +126,7 @@ impl GitHostingProvider for Gitlab {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use git::repository::repo_path;
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
@@ -209,11 +210,11 @@ mod tests {
|
|||||||
owner: "zed-industries".into(),
|
owner: "zed-industries".into(),
|
||||||
repo: "zed".into(),
|
repo: "zed".into(),
|
||||||
},
|
},
|
||||||
BuildPermalinkParams {
|
BuildPermalinkParams::new(
|
||||||
sha: "e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7",
|
"e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7",
|
||||||
path: "crates/editor/src/git/permalink.rs",
|
&repo_path("crates/editor/src/git/permalink.rs"),
|
||||||
selection: None,
|
None,
|
||||||
},
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
let expected_url = "https://gitlab.com/zed-industries/zed/-/blob/e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7/crates/editor/src/git/permalink.rs";
|
let expected_url = "https://gitlab.com/zed-industries/zed/-/blob/e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7/crates/editor/src/git/permalink.rs";
|
||||||
@@ -227,11 +228,11 @@ mod tests {
|
|||||||
owner: "zed-industries".into(),
|
owner: "zed-industries".into(),
|
||||||
repo: "zed".into(),
|
repo: "zed".into(),
|
||||||
},
|
},
|
||||||
BuildPermalinkParams {
|
BuildPermalinkParams::new(
|
||||||
sha: "e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7",
|
"e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7",
|
||||||
path: "crates/editor/src/git/permalink.rs",
|
&repo_path("crates/editor/src/git/permalink.rs"),
|
||||||
selection: Some(6..6),
|
Some(6..6),
|
||||||
},
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
let expected_url = "https://gitlab.com/zed-industries/zed/-/blob/e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7/crates/editor/src/git/permalink.rs#L7";
|
let expected_url = "https://gitlab.com/zed-industries/zed/-/blob/e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7/crates/editor/src/git/permalink.rs#L7";
|
||||||
@@ -245,11 +246,11 @@ mod tests {
|
|||||||
owner: "zed-industries".into(),
|
owner: "zed-industries".into(),
|
||||||
repo: "zed".into(),
|
repo: "zed".into(),
|
||||||
},
|
},
|
||||||
BuildPermalinkParams {
|
BuildPermalinkParams::new(
|
||||||
sha: "e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7",
|
"e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7",
|
||||||
path: "crates/editor/src/git/permalink.rs",
|
&repo_path("crates/editor/src/git/permalink.rs"),
|
||||||
selection: Some(23..47),
|
Some(23..47),
|
||||||
},
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
let expected_url = "https://gitlab.com/zed-industries/zed/-/blob/e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7/crates/editor/src/git/permalink.rs#L24-48";
|
let expected_url = "https://gitlab.com/zed-industries/zed/-/blob/e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7/crates/editor/src/git/permalink.rs#L24-48";
|
||||||
@@ -266,11 +267,11 @@ mod tests {
|
|||||||
owner: "zed-industries".into(),
|
owner: "zed-industries".into(),
|
||||||
repo: "zed".into(),
|
repo: "zed".into(),
|
||||||
},
|
},
|
||||||
BuildPermalinkParams {
|
BuildPermalinkParams::new(
|
||||||
sha: "e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7",
|
"e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7",
|
||||||
path: "crates/editor/src/git/permalink.rs",
|
&repo_path("crates/editor/src/git/permalink.rs"),
|
||||||
selection: None,
|
None,
|
||||||
},
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
let expected_url = "https://gitlab.some-enterprise.com/zed-industries/zed/-/blob/e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7/crates/editor/src/git/permalink.rs";
|
let expected_url = "https://gitlab.some-enterprise.com/zed-industries/zed/-/blob/e6ebe7974deb6bb6cc0e2595c8ec31f0c71084b7/crates/editor/src/git/permalink.rs";
|
||||||
@@ -287,11 +288,11 @@ mod tests {
|
|||||||
owner: "zed-industries".into(),
|
owner: "zed-industries".into(),
|
||||||
repo: "zed".into(),
|
repo: "zed".into(),
|
||||||
},
|
},
|
||||||
BuildPermalinkParams {
|
BuildPermalinkParams::new(
|
||||||
sha: "b2efec9824c45fcc90c9a7eb107a50d1772a60aa",
|
"b2efec9824c45fcc90c9a7eb107a50d1772a60aa",
|
||||||
path: "crates/zed/src/main.rs",
|
&repo_path("crates/zed/src/main.rs"),
|
||||||
selection: None,
|
None,
|
||||||
},
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
let expected_url = "https://gitlab-instance.big-co.com/zed-industries/zed/-/blob/b2efec9824c45fcc90c9a7eb107a50d1772a60aa/crates/zed/src/main.rs";
|
let expected_url = "https://gitlab-instance.big-co.com/zed-industries/zed/-/blob/b2efec9824c45fcc90c9a7eb107a50d1772a60aa/crates/zed/src/main.rs";
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ impl GitHostingProvider for Sourcehut {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use git::repository::repo_path;
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
@@ -145,11 +146,11 @@ mod tests {
|
|||||||
owner: "zed-industries".into(),
|
owner: "zed-industries".into(),
|
||||||
repo: "zed".into(),
|
repo: "zed".into(),
|
||||||
},
|
},
|
||||||
BuildPermalinkParams {
|
BuildPermalinkParams::new(
|
||||||
sha: "faa6f979be417239b2e070dbbf6392b909224e0b",
|
"faa6f979be417239b2e070dbbf6392b909224e0b",
|
||||||
path: "crates/editor/src/git/permalink.rs",
|
&repo_path("crates/editor/src/git/permalink.rs"),
|
||||||
selection: None,
|
None,
|
||||||
},
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
let expected_url = "https://git.sr.ht/~zed-industries/zed/tree/faa6f979be417239b2e070dbbf6392b909224e0b/item/crates/editor/src/git/permalink.rs";
|
let expected_url = "https://git.sr.ht/~zed-industries/zed/tree/faa6f979be417239b2e070dbbf6392b909224e0b/item/crates/editor/src/git/permalink.rs";
|
||||||
@@ -163,11 +164,11 @@ mod tests {
|
|||||||
owner: "zed-industries".into(),
|
owner: "zed-industries".into(),
|
||||||
repo: "zed.git".into(),
|
repo: "zed.git".into(),
|
||||||
},
|
},
|
||||||
BuildPermalinkParams {
|
BuildPermalinkParams::new(
|
||||||
sha: "faa6f979be417239b2e070dbbf6392b909224e0b",
|
"faa6f979be417239b2e070dbbf6392b909224e0b",
|
||||||
path: "crates/editor/src/git/permalink.rs",
|
&repo_path("crates/editor/src/git/permalink.rs"),
|
||||||
selection: None,
|
None,
|
||||||
},
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
let expected_url = "https://git.sr.ht/~zed-industries/zed.git/tree/faa6f979be417239b2e070dbbf6392b909224e0b/item/crates/editor/src/git/permalink.rs";
|
let expected_url = "https://git.sr.ht/~zed-industries/zed.git/tree/faa6f979be417239b2e070dbbf6392b909224e0b/item/crates/editor/src/git/permalink.rs";
|
||||||
@@ -181,11 +182,11 @@ mod tests {
|
|||||||
owner: "zed-industries".into(),
|
owner: "zed-industries".into(),
|
||||||
repo: "zed".into(),
|
repo: "zed".into(),
|
||||||
},
|
},
|
||||||
BuildPermalinkParams {
|
BuildPermalinkParams::new(
|
||||||
sha: "faa6f979be417239b2e070dbbf6392b909224e0b",
|
"faa6f979be417239b2e070dbbf6392b909224e0b",
|
||||||
path: "crates/editor/src/git/permalink.rs",
|
&repo_path("crates/editor/src/git/permalink.rs"),
|
||||||
selection: Some(6..6),
|
Some(6..6),
|
||||||
},
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
let expected_url = "https://git.sr.ht/~zed-industries/zed/tree/faa6f979be417239b2e070dbbf6392b909224e0b/item/crates/editor/src/git/permalink.rs#L7";
|
let expected_url = "https://git.sr.ht/~zed-industries/zed/tree/faa6f979be417239b2e070dbbf6392b909224e0b/item/crates/editor/src/git/permalink.rs#L7";
|
||||||
@@ -199,11 +200,11 @@ mod tests {
|
|||||||
owner: "zed-industries".into(),
|
owner: "zed-industries".into(),
|
||||||
repo: "zed".into(),
|
repo: "zed".into(),
|
||||||
},
|
},
|
||||||
BuildPermalinkParams {
|
BuildPermalinkParams::new(
|
||||||
sha: "faa6f979be417239b2e070dbbf6392b909224e0b",
|
"faa6f979be417239b2e070dbbf6392b909224e0b",
|
||||||
path: "crates/editor/src/git/permalink.rs",
|
&repo_path("crates/editor/src/git/permalink.rs"),
|
||||||
selection: Some(23..47),
|
Some(23..47),
|
||||||
},
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
let expected_url = "https://git.sr.ht/~zed-industries/zed/tree/faa6f979be417239b2e070dbbf6392b909224e0b/item/crates/editor/src/git/permalink.rs#L24-48";
|
let expected_url = "https://git.sr.ht/~zed-industries/zed/tree/faa6f979be417239b2e070dbbf6392b909224e0b/item/crates/editor/src/git/permalink.rs#L24-48";
|
||||||
|
|||||||
@@ -969,8 +969,6 @@ impl GitStore {
|
|||||||
get_permalink_in_rust_registry_src(provider_registry, file_path, selection)
|
get_permalink_in_rust_registry_src(provider_registry, file_path, selection)
|
||||||
.context("no permalink available")
|
.context("no permalink available")
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO remote case
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let buffer_id = buffer.read(cx).remote_id();
|
let buffer_id = buffer.read(cx).remote_id();
|
||||||
@@ -999,15 +997,9 @@ impl GitStore {
|
|||||||
parse_git_remote_url(provider_registry, &origin_url)
|
parse_git_remote_url(provider_registry, &origin_url)
|
||||||
.context("parsing Git remote URL")?;
|
.context("parsing Git remote URL")?;
|
||||||
|
|
||||||
let path = repo_path.as_unix_str();
|
|
||||||
|
|
||||||
Ok(provider.build_permalink(
|
Ok(provider.build_permalink(
|
||||||
remote,
|
remote,
|
||||||
BuildPermalinkParams {
|
BuildPermalinkParams::new(&sha, &repo_path, Some(selection)),
|
||||||
sha: &sha,
|
|
||||||
path,
|
|
||||||
selection: Some(selection),
|
|
||||||
},
|
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
RepositoryState::Remote { project_id, client } => {
|
RepositoryState::Remote { project_id, client } => {
|
||||||
@@ -4913,11 +4905,15 @@ fn get_permalink_in_rust_registry_src(
|
|||||||
let path = PathBuf::from(cargo_vcs_info.path_in_vcs).join(path.strip_prefix(dir).unwrap());
|
let path = PathBuf::from(cargo_vcs_info.path_in_vcs).join(path.strip_prefix(dir).unwrap());
|
||||||
let permalink = provider.build_permalink(
|
let permalink = provider.build_permalink(
|
||||||
remote,
|
remote,
|
||||||
BuildPermalinkParams {
|
BuildPermalinkParams::new(
|
||||||
sha: &cargo_vcs_info.git.sha1,
|
&cargo_vcs_info.git.sha1,
|
||||||
path: &path.to_string_lossy(),
|
&RepoPath(
|
||||||
selection: Some(selection),
|
RelPath::new(&path, PathStyle::local())
|
||||||
},
|
.context("invalid path")?
|
||||||
|
.into_arc(),
|
||||||
|
),
|
||||||
|
Some(selection),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
Ok(permalink)
|
Ok(permalink)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user