diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 335caea..d0c30fe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,8 +10,8 @@ concurrency: group: ${{ github.ref }}-ci cancel-in-progress: true jobs: - pr_conventional_commit: - name: Conventional Commit + conventional_commit: + name: Conventional Commits if: ${{ github.ref != 'refs/heads/main' }} runs-on: ubuntu-latest steps: @@ -34,7 +34,7 @@ jobs: args: src --config .luacheckrc - uses: stevearc/nvim-typecheck-action@v1 with: - path: src + path: src/giturlparser.lua level: Information configpath: ".luarc.json" - uses: stefanzweifel/git-auto-commit-action@v4 @@ -46,7 +46,7 @@ jobs: name: Unit Test strategy: matrix: - lua_version: ["5.1", "5.2", "5.3", "luajit"] + lua_version: ["5.1", "5.2", "5.3", "luajit-openresty"] needs: - luacheck runs-on: ubuntu-latest @@ -56,6 +56,25 @@ jobs: with: luaVersion: ${{ matrix.lua_version }} - uses: leafo/gh-actions-luarocks@v4 + - name: Run Tests + run: | + echo 'pwd' + echo $PWD + echo 'ls-1' + ls -lha + luarocks install busted + busted . + code_coverage: + name: Code Coverage + needs: + - luacheck + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: leafo/gh-actions-lua@v10 + with: + luaVersion: "luajit-openresty" + - uses: leafo/gh-actions-luarocks@v4 - name: Run Tests run: | echo 'pwd' @@ -63,12 +82,8 @@ jobs: echo 'ls-1' ls -lha luarocks install luacov - luarocks install cluacov luarocks install busted busted --coverage . - # - uses: lunarmodules/busted@v2 - # with: - # args: . - name: Generate Coverage Reports run: | echo "ls ." @@ -79,7 +94,7 @@ jobs: ls -l . echo "cat ./luacov.report.out" cat ./luacov.report.out - - uses: codecov/codecov-action@v3 + - uses: codecov/codecov-action@v4 with: files: luacov.report.out env: @@ -89,6 +104,7 @@ jobs: if: ${{ github.ref == 'refs/heads/main' }} needs: - unit_test + - code_coverage runs-on: ubuntu-latest steps: - uses: google-github-actions/release-please-action@v3 @@ -110,7 +126,7 @@ jobs: if: ${{ steps.release.outputs.release_created }} run: | luarocks install dkjson - luarocks write_rockspec --lua-versions="5.1,5.2,5.3,5.4" --tag=${{ steps.release.outputs.tag_name }} --detailed="Pure Lua implemented git URL parsing library" --summary="Pure Lua implemented git URL parsing library" --license=MIT --homepage="https://github.com/linrongbin16/giturlparser.lua" + luarocks write_rockspec --lua-versions="5.1,5.2,5.3,5.4" --tag=${{ steps.release.outputs.tag_name }} --detailed="Git URL parsing library for Lua." --summary="Git URL parsing library for Lua." --license=MIT --homepage="https://github.com/linrongbin16/giturlparser.lua" echo 'ls-1' ls -lh mv giturlparser.lua-${{steps.release.outputs.major}}.${{steps.release.outputs.minor}}.${{steps.release.outputs.patch}}-1.rockspec giturlparser-${{steps.release.outputs.major}}.${{steps.release.outputs.minor}}.${{steps.release.outputs.patch}}-1.rockspec diff --git a/CHANGELOG.md b/CHANGELOG.md index a94e826..f755a66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## [1.0.8](https://github.com/linrongbin16/giturlparser.lua/compare/v1.0.7...v1.0.8) (2024-11-22) + + +### Bug Fixes + +* **port:** fix host ends with colon but port is empty ([#36](https://github.com/linrongbin16/giturlparser.lua/issues/36)) ([a2d473a](https://github.com/linrongbin16/giturlparser.lua/commit/a2d473a129500069bcbc836d3ad572225a765a29)) + ## [1.0.7](https://github.com/linrongbin16/giturlparser.lua/compare/v1.0.6...v1.0.7) (2024-01-08) diff --git a/README.md b/README.md index 2b985c6..499dc06 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@
-Pure Lua implemented git URL parsing library, e.g. the output of git remote get-url origin
.
+Git url parsing library for lua, e.g. the output of git remote get-url origin
.
git remot
- [Requirements](#requirements)
- [Features](#features)
- [Install](#install)
+- [Patterns](#patterns)
+ - [Full Protocols](#full-protocols)
+ - [SSH Omitted Protocols](#ssh-omitted-protocols)
+ - [Local File System](#local-file-system)
- [API](#api)
- [Types](#types)
- [`giturlparser.GitUrlPos`](#giturlparsergiturlpos)
@@ -33,21 +37,30 @@ Pure Lua implemented git URL parsing library, e.g. the output of git remot
## Features
-Single file & zero dependency.
+* Single file & zero dependency.
+* Full [Git Protocols](https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols) support (see [Patterns](#patterns)).
-Full [Git Protocols](https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols) support (see below).
+## Install
+
+```bash
+luarocks install giturlparser
+```
+
+## Patterns
+
+There are (mainly) three types of git url pattern:
> [!NOTE]
>
-> Below pattern are (just easier to help explain the parsing algorithm) written in a regex-like syntax:
+> They are (just help to explain) written with a regex-like syntax:
>
> 1. The `{}` contains parsed components returned from [`giturlparser.GitUrlInfo`](#giturlparsergiturlinfo).
> 2. The `[]` contains optional (0 or 1) component.
-> 3. The `[]*` contains zero or more (≥ 0) component.
-> 4. The `[]+` contains 1 or more (≥ 1) component.
+> 3. The `[]*` contains 0 or more component.
+> 4. The `[]+` contains 1 or more component.
> 5. The `|` inside `[]` is **_or_** operator.
-### Full Pattern
+### Full Protocols
`{protocol}://[[{user}[:{password}]@]{host}[:{port}]]/[{org}/]*{repo}`
@@ -61,7 +74,7 @@ For example:
- `file://user:passwd@host.xyz:port/path/to/the/repo.git`
- `file://~/home/to/the/repo.git`
-### Protocol Omitted Pattern
+### SSH Omitted Protocols
`[{user}[:{password}]@]{host}:[{org}/]*{repo}`
@@ -70,9 +83,9 @@ For example:
- `git@host.xyz:repo.git`
- `user:passwd@host.xyz:path/to/the/repo.git`
-### Local Pattern
+### Local File System
-`[.|..|~][/{org}]*/{repo}`
+`[[.|..|~]/][{org}/]*{repo}`
For example:
@@ -82,10 +95,6 @@ For example:
- `~/home/to/the/repo.git`
- `/usr/home/to/the/repo.git`
-## Install
-
-`luarocks install giturlparser`
-
## API
### Types
diff --git a/spec/giturlparser_spec.lua b/spec/giturlparser_spec.lua
index d096cee..c431032 100644
--- a/spec/giturlparser_spec.lua
+++ b/spec/giturlparser_spec.lua
@@ -7,9 +7,9 @@ describe("giturlparser", function()
-- local inspect = require("inspect")
local giturlparser = require("giturlparser")
- describe("[_make_path]", function()
+ describe("[_parse_path]", function()
it("repo.git", function()
- local actual = giturlparser._make_path("repo.git", 1)
+ local actual = giturlparser._parse_path("repo.git", 1)
assert_eq(actual.org, nil)
assert_eq(actual.org_pos, nil)
assert_eq(actual.repo, "repo.git")
@@ -20,7 +20,7 @@ describe("giturlparser", function()
assert_eq(actual.path_pos.end_pos, 8)
end)
it("repo.git/", function()
- local actual = giturlparser._make_path("repo.git/", 1)
+ local actual = giturlparser._parse_path("repo.git/", 1)
assert_eq(actual.org, nil)
assert_eq(actual.org_pos, nil)
assert_eq(actual.repo, "repo.git")
@@ -31,7 +31,7 @@ describe("giturlparser", function()
assert_eq(actual.path_pos.end_pos, 9)
end)
it("/repo.git/", function()
- local actual = giturlparser._make_path("/repo.git/", 1)
+ local actual = giturlparser._parse_path("/repo.git/", 1)
assert_eq(actual.org, nil)
assert_eq(actual.org_pos, nil)
assert_eq(actual.repo, "repo.git")
@@ -42,7 +42,7 @@ describe("giturlparser", function()
assert_eq(actual.path_pos.end_pos, 10)
end)
it("/repo.git", function()
- local actual = giturlparser._make_path("/repo.git", 1)
+ local actual = giturlparser._parse_path("/repo.git", 1)
assert_eq(actual.org, nil)
assert_eq(actual.org_pos, nil)
assert_eq(actual.repo, "repo.git")
@@ -53,7 +53,7 @@ describe("giturlparser", function()
assert_eq(actual.path_pos.end_pos, 9)
end)
it("path/to/the/repo.git", function()
- local actual = giturlparser._make_path("path/to/the/repo.git", 1)
+ local actual = giturlparser._parse_path("path/to/the/repo.git", 1)
assert_eq(actual.org, "path/to/the")
assert_eq(actual.org_pos.start_pos, 1)
assert_eq(actual.org_pos.end_pos, 11)
@@ -65,7 +65,7 @@ describe("giturlparser", function()
assert_eq(actual.path_pos.end_pos, 20)
end)
it("path/to/the/repo.git/", function()
- local actual = giturlparser._make_path("path/to/the/repo.git/", 1)
+ local actual = giturlparser._parse_path("path/to/the/repo.git/", 1)
assert_eq(actual.org, "path/to/the")
assert_eq(actual.org_pos.start_pos, 1)
assert_eq(actual.org_pos.end_pos, 11)
@@ -77,7 +77,7 @@ describe("giturlparser", function()
assert_eq(actual.path_pos.end_pos, 21)
end)
it("/abspath/to/the/repo.git", function()
- local actual = giturlparser._make_path("/abspath/to/the/repo.git", 1)
+ local actual = giturlparser._parse_path("/abspath/to/the/repo.git", 1)
assert_eq(actual.org, "abspath/to/the")
assert_eq(actual.org_pos.start_pos, 2)
assert_eq(actual.org_pos.end_pos, 15)
@@ -89,7 +89,7 @@ describe("giturlparser", function()
assert_eq(actual.path_pos.end_pos, 24)
end)
it("/abspath/to/the/repo.git/", function()
- local actual = giturlparser._make_path("/abspath/to/the/repo.git/", 1)
+ local actual = giturlparser._parse_path("/abspath/to/the/repo.git/", 1)
assert_eq(actual.org, "abspath/to/the")
assert_eq(actual.org_pos.start_pos, 2)
assert_eq(actual.org_pos.end_pos, 15)
@@ -101,7 +101,7 @@ describe("giturlparser", function()
assert_eq(actual.path_pos.end_pos, 25)
end)
it("~/path/to/the/repo.git", function()
- local actual = giturlparser._make_path("~/path/to/the/repo.git", 1)
+ local actual = giturlparser._parse_path("~/path/to/the/repo.git", 1)
assert_eq(actual.org, "~/path/to/the")
assert_eq(actual.org_pos.start_pos, 1)
assert_eq(actual.org_pos.end_pos, 13)
@@ -113,7 +113,7 @@ describe("giturlparser", function()
assert_eq(actual.path_pos.end_pos, 22)
end)
it("~/path/to/the/repo.git/", function()
- local actual = giturlparser._make_path("~/path/to/the/repo.git/", 1)
+ local actual = giturlparser._parse_path("~/path/to/the/repo.git/", 1)
assert_eq(actual.org, "~/path/to/the")
assert_eq(actual.org_pos.start_pos, 1)
assert_eq(actual.org_pos.end_pos, 13)
@@ -125,7 +125,7 @@ describe("giturlparser", function()
assert_eq(actual.path_pos.end_pos, 23)
end)
it("./path/to/the/repo.git", function()
- local actual = giturlparser._make_path("./path/to/the/repo.git", 1)
+ local actual = giturlparser._parse_path("./path/to/the/repo.git", 1)
assert_eq(actual.org, "./path/to/the")
assert_eq(actual.org_pos.start_pos, 1)
assert_eq(actual.org_pos.end_pos, 13)
@@ -137,7 +137,7 @@ describe("giturlparser", function()
assert_eq(actual.path_pos.end_pos, 22)
end)
it("../path/to/the/repo.git/", function()
- local actual = giturlparser._make_path("../path/to/the/repo.git/", 1)
+ local actual = giturlparser._parse_path("../path/to/the/repo.git/", 1)
assert_eq(actual.org, "../path/to/the")
assert_eq(actual.org_pos.start_pos, 1)
assert_eq(actual.org_pos.end_pos, 14)
@@ -150,9 +150,9 @@ describe("giturlparser", function()
end)
end)
- describe("[_make_host]", function()
+ describe("[_parse_host]", function()
it("github.com/org/repo.git", function()
- local actual = giturlparser._make_host("github.com/org/repo.git", 1)
+ local actual = giturlparser._parse_host("github.com/org/repo.git", 1)
-- print(string.format("_make_host-1:%s\n", inspect(actual)))
assert_eq(actual.host, "github.com")
assert_eq(actual.host_pos.start_pos, 1)
@@ -171,7 +171,7 @@ describe("giturlparser", function()
assert_eq(path_obj.path_pos.end_pos, 23)
end)
it("github.com/org/repo.git/", function()
- local actual = giturlparser._make_host("github.com/org/repo.git/", 1)
+ local actual = giturlparser._parse_host("github.com/org/repo.git/", 1)
-- print(string.format("_make_host-2:%s\n", inspect(actual)))
assert_eq(actual.host, "github.com")
assert_eq(actual.host_pos.start_pos, 1)
@@ -190,7 +190,7 @@ describe("giturlparser", function()
assert_eq(path_obj.path_pos.end_pos, 24)
end)
it("github.com:port/org/repo.git", function()
- local actual = giturlparser._make_host("github.com:port/org/repo.git", 1)
+ local actual = giturlparser._parse_host("github.com:port/org/repo.git", 1)
-- print(string.format("_make_host-3:%s\n", inspect(actual)))
assert_eq(actual.host, "github.com")
assert_eq(actual.host_pos.start_pos, 1)
@@ -210,7 +210,8 @@ describe("giturlparser", function()
assert_eq(path_obj.path_pos.end_pos, 28)
end)
it("127.0.0.1:12345/org/repo.git/", function()
- local actual = giturlparser._make_host("127.0.0.1:12345/org/repo.git/", 1)
+ local actual =
+ giturlparser._parse_host("127.0.0.1:12345/org/repo.git/", 1)
-- print(string.format("_make_host-4:%s\n", inspect(actual)))
assert_eq(actual.host, "127.0.0.1")
assert_eq(actual.host_pos.start_pos, 1)
@@ -230,7 +231,7 @@ describe("giturlparser", function()
assert_eq(path_obj.path_pos.end_pos, 29)
end)
it("github.com/repo.git", function()
- local actual = giturlparser._make_host("github.com/repo.git", 1)
+ local actual = giturlparser._parse_host("github.com/repo.git", 1)
-- print(string.format("_make_host-3:%s\n", inspect(actual)))
assert_eq(actual.host, "github.com")
assert_eq(actual.host_pos.start_pos, 1)
@@ -248,7 +249,7 @@ describe("giturlparser", function()
assert_eq(path_obj.path_pos.end_pos, 19)
end)
it("127.0.0.1:12345/repo.git/", function()
- local actual = giturlparser._make_host("127.0.0.1:12345/repo.git/", 1)
+ local actual = giturlparser._parse_host("127.0.0.1:12345/repo.git/", 1)
-- print(string.format("_make_host-4:%s\n", inspect(actual)))
assert_eq(actual.host, "127.0.0.1")
assert_eq(actual.host_pos.start_pos, 1)
@@ -266,12 +267,31 @@ describe("giturlparser", function()
assert_eq(path_obj.path_pos.start_pos, 16)
assert_eq(path_obj.path_pos.end_pos, 25)
end)
+ it("github.com:/repo.git", function()
+ local actual = giturlparser._parse_host("github.com:/repo.git", 1)
+ -- print(string.format("_make_host-5:%s\n", "github.com:/repo.git"))
+ -- print(string.format("_make_host-5:%s\n", inspect(actual)))
+ assert_eq(actual.host, "github.com")
+ assert_eq(actual.host_pos.start_pos, 1)
+ assert_eq(actual.host_pos.end_pos, 10)
+ assert_eq(actual.port, nil)
+ assert_eq(actual.port_pos, nil)
+ local path_obj = actual.path_obj
+ assert_eq(path_obj.org, nil)
+ assert_eq(path_obj.org_pos, nil)
+ assert_eq(path_obj.repo, "repo.git")
+ assert_eq(path_obj.repo_pos.start_pos, 13)
+ assert_eq(path_obj.repo_pos.end_pos, 20)
+ assert_eq(path_obj.path, "/repo.git")
+ assert_eq(path_obj.path_pos.start_pos, 12)
+ assert_eq(path_obj.path_pos.end_pos, 20)
+ end)
end)
- describe("[_make_host_with_omit_ssh]", function()
+ describe("[_parse_host_with_omit_ssh]", function()
it("github.com:org/repo.git", function()
local actual =
- giturlparser._make_host_with_omit_ssh("github.com:org/repo.git", 1)
+ giturlparser._parse_host_with_omit_ssh("github.com:org/repo.git", 1)
-- print(string.format("_make_host_with_omit_ssh-1:%s\n", inspect(actual)))
assert_eq(actual.host, "github.com")
assert_eq(actual.host_pos.start_pos, 1)
@@ -291,7 +311,7 @@ describe("giturlparser", function()
end)
it("github.com:org/repo.git/", function()
local actual =
- giturlparser._make_host_with_omit_ssh("github.com:org/repo.git/", 1)
+ giturlparser._parse_host_with_omit_ssh("github.com:org/repo.git/", 1)
-- print(string.format("_make_host_with_omit_ssh-2:%s\n", inspect(actual)))
assert_eq(actual.host, "github.com")
assert_eq(actual.host_pos.start_pos, 1)
@@ -311,7 +331,7 @@ describe("giturlparser", function()
end)
it("github.com:repo.git", function()
local actual =
- giturlparser._make_host_with_omit_ssh("github.com:repo.git", 1)
+ giturlparser._parse_host_with_omit_ssh("github.com:repo.git", 1)
-- print(string.format("_make_host_with_omit_ssh-3:%s\n", inspect(actual)))
assert_eq(actual.host, "github.com")
assert_eq(actual.host_pos.start_pos, 1)
@@ -330,7 +350,7 @@ describe("giturlparser", function()
end)
it("127.0.0.1:repo.git/", function()
local actual =
- giturlparser._make_host_with_omit_ssh("127.0.0.1:repo.git/", 1)
+ giturlparser._parse_host_with_omit_ssh("127.0.0.1:repo.git/", 1)
-- print(string.format("_make_host_with_omit_ssh-4:%s\n", inspect(actual)))
assert_eq(actual.host, "127.0.0.1")
assert_eq(actual.host_pos.start_pos, 1)
@@ -349,9 +369,9 @@ describe("giturlparser", function()
end)
end)
- describe("[_make_user]", function()
+ describe("[_parse_user]", function()
it("github.com/org/repo.git", function()
- local actual = giturlparser._make_user("github.com/org/repo.git", 1)
+ local actual = giturlparser._parse_user("github.com/org/repo.git", 1)
-- print(string.format("_make_user-1:%s\n", inspect(actual)))
assert_eq(actual.user, nil)
assert_eq(actual.user_pos, nil)
@@ -375,7 +395,7 @@ describe("giturlparser", function()
assert_eq(path_obj.path_pos.end_pos, 23)
end)
it("github.com/org/repo.git/", function()
- local actual = giturlparser._make_user("github.com/org/repo.git/", 1)
+ local actual = giturlparser._parse_user("github.com/org/repo.git/", 1)
-- print(string.format("_make_user-2:%s\n", inspect(actual)))
assert_eq(actual.user, nil)
assert_eq(actual.user_pos, nil)
@@ -399,7 +419,7 @@ describe("giturlparser", function()
assert_eq(path_obj.path_pos.end_pos, 24)
end)
it("user@github.com/org/repo.git", function()
- local actual = giturlparser._make_user("user@github.com/org/repo.git", 1)
+ local actual = giturlparser._parse_user("user@github.com/org/repo.git", 1)
-- print(string.format("_make_user-3:%s\n", inspect(actual)))
assert_eq(actual.user, "user")
assert_eq(actual.user_pos.start_pos, 1)
@@ -425,7 +445,7 @@ describe("giturlparser", function()
end)
it("user:passwd@github.com/org/repo.git/", function()
local actual =
- giturlparser._make_user("user:passwd@github.com/org/repo.git/", 1)
+ giturlparser._parse_user("user:passwd@github.com/org/repo.git/", 1)
-- print(string.format("_make_user-4:%s\n", inspect(actual)))
assert_eq(actual.user, "user")
assert_eq(actual.user_pos.start_pos, 1)
@@ -451,7 +471,7 @@ describe("giturlparser", function()
assert_eq(path_obj.path_pos.end_pos, 36)
end)
it("github.com:port/org/repo.git", function()
- local actual = giturlparser._make_user("github.com:port/org/repo.git", 1)
+ local actual = giturlparser._parse_user("github.com:port/org/repo.git", 1)
-- print(string.format("_make_user-5:%s\n", inspect(actual)))
assert_eq(actual.user, nil)
assert_eq(actual.user_pos, nil)
@@ -476,7 +496,8 @@ describe("giturlparser", function()
assert_eq(path_obj.path_pos.end_pos, 28)
end)
it("127.0.0.1:12345/org/repo.git/", function()
- local actual = giturlparser._make_user("127.0.0.1:12345/org/repo.git/", 1)
+ local actual =
+ giturlparser._parse_user("127.0.0.1:12345/org/repo.git/", 1)
-- print(string.format("_make_user-6:%s\n", inspect(actual)))
assert_eq(actual.user, nil)
assert_eq(actual.user_pos, nil)
@@ -501,8 +522,10 @@ describe("giturlparser", function()
assert_eq(path_obj.path_pos.end_pos, 29)
end)
it("user2:passwd2@github.com:port/org/repo.git", function()
- local actual =
- giturlparser._make_user("user2:passwd2@github.com:port/org/repo.git", 1)
+ local actual = giturlparser._parse_user(
+ "user2:passwd2@github.com:port/org/repo.git",
+ 1
+ )
-- print(string.format("_make_user-7:%s\n", inspect(actual)))
assert_eq(actual.user, "user2")
assert_eq(actual.user_pos.start_pos, 1)
@@ -530,7 +553,7 @@ describe("giturlparser", function()
end)
it("git@127.0.0.1:12345/org/repo.git/", function()
local actual =
- giturlparser._make_user("git@127.0.0.1:12345/org/repo.git/", 1)
+ giturlparser._parse_user("git@127.0.0.1:12345/org/repo.git/", 1)
-- print(string.format("_make_user-6:%s\n", inspect(actual)))
assert_eq(actual.user, "git")
assert_eq(actual.user_pos.start_pos, 1)
@@ -556,7 +579,7 @@ describe("giturlparser", function()
assert_eq(path_obj.path_pos.end_pos, 33)
end)
it("github.com/repo.git", function()
- local actual = giturlparser._make_user("github.com/repo.git", 1)
+ local actual = giturlparser._parse_user("github.com/repo.git", 1)
-- print(string.format("_make_user-7:%s\n", inspect(actual)))
assert_eq(actual.user, nil)
assert_eq(actual.user_pos, nil)
@@ -579,7 +602,7 @@ describe("giturlparser", function()
assert_eq(path_obj.path_pos.end_pos, 19)
end)
it("127.0.0.1:12345/repo.git/", function()
- local actual = giturlparser._make_user("127.0.0.1:12345/repo.git/", 1)
+ local actual = giturlparser._parse_user("127.0.0.1:12345/repo.git/", 1)
-- print(string.format("_make_user-8:%s\n", inspect(actual)))
assert_eq(actual.user, nil)
assert_eq(actual.user_pos, nil)
@@ -603,7 +626,7 @@ describe("giturlparser", function()
assert_eq(path_obj.path_pos.end_pos, 25)
end)
it("git@github.com/repo.git", function()
- local actual = giturlparser._make_user("git@github.com/repo.git", 1)
+ local actual = giturlparser._parse_user("git@github.com/repo.git", 1)
-- print(string.format("_make_user-9:%s\n", inspect(actual)))
assert_eq(actual.user, "git")
assert_eq(actual.user_pos.start_pos, 1)
@@ -628,7 +651,7 @@ describe("giturlparser", function()
end)
it("linrongbin:123456@127.0.0.1:12345/repo.git/", function()
local actual =
- giturlparser._make_user("linrongbin:123@127.0.0.1:12345/repo.git/", 1)
+ giturlparser._parse_user("linrongbin:123@127.0.0.1:12345/repo.git/", 1)
-- print(string.format("_make_user-8:%s\n", inspect(actual)))
assert_eq(actual.user, "linrongbin")
assert_eq(actual.user_pos.start_pos, 1)
@@ -655,9 +678,10 @@ describe("giturlparser", function()
end)
end)
- describe("[_make_user with omitted ssh]", function()
+ describe("[_parse_user with omitted ssh]", function()
it("github.com:org/repo.git", function()
- local actual = giturlparser._make_user("github.com:org/repo.git", 1, true)
+ local actual =
+ giturlparser._parse_user("github.com:org/repo.git", 1, true)
-- print(string.format("_make_user_omit-1:%s\n", inspect(actual)))
assert_eq(actual.user, nil)
assert_eq(actual.user_pos, nil)
@@ -682,7 +706,7 @@ describe("giturlparser", function()
end)
it("github.com:org/repo.git/", function()
local actual =
- giturlparser._make_user("github.com:org/repo.git/", 1, true)
+ giturlparser._parse_user("github.com:org/repo.git/", 1, true)
-- print(string.format("_make_user_omit-2:%s\n", inspect(actual)))
assert_eq(actual.user, nil)
assert_eq(actual.user_pos, nil)
@@ -707,7 +731,7 @@ describe("giturlparser", function()
end)
it("user@github.com:repo.git", function()
local actual =
- giturlparser._make_user("user@github.com:repo.git", 1, true)
+ giturlparser._parse_user("user@github.com:repo.git", 1, true)
-- print(string.format("_make_user_omit-3:%s\n", inspect(actual)))
assert_eq(actual.user, "user")
assert_eq(actual.user_pos.start_pos, 1)
@@ -732,7 +756,7 @@ describe("giturlparser", function()
end)
it("user:passwd@127.0.0.1:repo.git/", function()
local actual =
- giturlparser._make_user("user:passwd@127.0.0.1:repo.git/", 1, true)
+ giturlparser._parse_user("user:passwd@127.0.0.1:repo.git/", 1, true)
-- print(string.format("_make_user_omit-4:%s\n", inspect(actual)))
assert_eq(actual.user, "user")
assert_eq(actual.user_pos.start_pos, 1)
@@ -757,7 +781,7 @@ describe("giturlparser", function()
assert_eq(path_obj.path_pos.end_pos, 31)
end)
it("github.com:repo.git", function()
- local actual = giturlparser._make_user("github.com:repo.git", 1, true)
+ local actual = giturlparser._parse_user("github.com:repo.git", 1, true)
-- print(string.format("_make_user_omit-5:%s\n", inspect(actual)))
assert_eq(actual.user, nil)
assert_eq(actual.user_pos, nil)
@@ -780,7 +804,7 @@ describe("giturlparser", function()
assert_eq(path_obj.path_pos.end_pos, 19)
end)
it("127.0.0.1:repo.git/", function()
- local actual = giturlparser._make_user("127.0.0.1:repo.git/", 1, true)
+ local actual = giturlparser._parse_user("127.0.0.1:repo.git/", 1, true)
-- print(string.format("_make_user_omit-6:%s\n", inspect(actual)))
assert_eq(actual.user, nil)
assert_eq(actual.user_pos, nil)
@@ -804,7 +828,7 @@ describe("giturlparser", function()
end)
it("user@github.com:repo.git", function()
local actual =
- giturlparser._make_user("user@github.com:repo.git", 1, true)
+ giturlparser._parse_user("user@github.com:repo.git", 1, true)
-- print(string.format("_make_user_omit-7:%s\n", inspect(actual)))
assert_eq(actual.user, "user")
assert_eq(actual.user_pos.start_pos, 1)
@@ -829,7 +853,7 @@ describe("giturlparser", function()
end)
it("git:pass@127.0.0.1:repo.git/", function()
local actual =
- giturlparser._make_user("git:pass@127.0.0.1:repo.git/", 1, true)
+ giturlparser._parse_user("git:pass@127.0.0.1:repo.git/", 1, true)
-- print(string.format("_make_user_omit-9:%s\n", inspect(actual)))
assert_eq(actual.user, "git")
assert_eq(actual.user_pos.start_pos, 1)
diff --git a/src/giturlparser.lua b/src/giturlparser.lua
index 639dd81..911d4b2 100644
--- a/src/giturlparser.lua
+++ b/src/giturlparser.lua
@@ -1,3 +1,4 @@
+-- local inspect = require("inspect")
local M = {}
-- utils {
@@ -144,11 +145,9 @@ end
--- @param p string
--- @param start integer
--- @return giturlparser._GitUrlPath
-M._make_path = function(p, start)
+M._parse_path = function(p, start)
assert(type(start) == "number")
- -- local inspect = require("inspect")
-
local endswith_slash = M._endswith(p, "/")
local org = nil
@@ -206,7 +205,7 @@ end
--- @param p string
--- @param start integer
--- @return giturlparser._GitUrlHost
-M._make_host = function(p, start)
+M._parse_host = function(p, start)
assert(type(start) == "number")
assert(not M._startswith(p, "/"))
@@ -227,13 +226,24 @@ M._make_host = function(p, start)
-- find first slash '/' (after second ':'), the end position of port, start position of path
local first_slash_pos = M._find(p, "/", first_colon_pos + 1)
- if
- type(first_slash_pos) == "number"
- and first_slash_pos > first_colon_pos + 1
- then
- -- port end with '/'
- port, port_pos = M._make(p, first_colon_pos + 1, first_slash_pos - 1)
- path_obj = M._make_path(p, first_slash_pos)
+ -- print(
+ -- string.format(
+ -- "_parse_host, start:%s, first_colon_pos:%s, first_slash_pos:%s\n",
+ -- inspect(start),
+ -- inspect(first_colon_pos),
+ -- inspect(first_slash_pos)
+ -- )
+ -- )
+ if type(first_slash_pos) == "number" then
+ if first_slash_pos > first_colon_pos + 1 then
+ -- port end with '/'
+ port, port_pos = M._make(p, first_colon_pos + 1, first_slash_pos - 1)
+ path_obj = M._parse_path(p, first_slash_pos)
+ else
+ assert(first_slash_pos == first_colon_pos + 1)
+ -- port is empty, host still end with '/'
+ path_obj = M._parse_path(p, first_slash_pos)
+ end
else
-- path not found, port end until url end
port, port_pos = M._make(p, first_colon_pos + 1, plen)
@@ -246,10 +256,10 @@ M._make_host = function(p, start)
if type(first_slash_pos) == "number" and first_slash_pos > start then
-- host end with '/'
host, host_pos = M._make(p, start, first_slash_pos - 1)
- path_obj = M._make_path(p, first_slash_pos)
+ path_obj = M._parse_path(p, first_slash_pos)
else
-- first slash not found, host is omitted, path end until url end
- path_obj = M._make_path(p, start)
+ path_obj = M._parse_path(p, start)
end
end
@@ -267,7 +277,7 @@ end
--- @param p string
--- @param start integer
--- @return giturlparser._GitUrlHost
-M._make_host_with_omit_ssh = function(p, start)
+M._parse_host_with_omit_ssh = function(p, start)
assert(type(start) == "number")
assert(not M._startswith(p, "/"))
@@ -285,10 +295,10 @@ M._make_host_with_omit_ssh = function(p, start)
if type(first_colon_pos) == "number" and first_colon_pos > start then
-- host end with ':', path start with ':'
host, host_pos = M._make(p, start, first_colon_pos - 1)
- path_obj = M._make_path(p, first_colon_pos + 1)
+ path_obj = M._parse_path(p, first_colon_pos + 1)
else
-- host not found, path start from beginning
- path_obj = M._make_path(p, start)
+ path_obj = M._parse_path(p, start)
end
return {
@@ -306,7 +316,7 @@ end
--- @param start integer
--- @param ssh_protocol_omitted boolean?
--- @return giturlparser._GitUrlUser
-M._make_user = function(p, start, ssh_protocol_omitted)
+M._parse_user = function(p, start, ssh_protocol_omitted)
assert(type(start) == "number")
assert(not M._startswith(p, "/"))
@@ -371,8 +381,8 @@ M._make_user = function(p, start, ssh_protocol_omitted)
-- )
-- )
host_obj = ssh_protocol_omitted
- and M._make_host_with_omit_ssh(p, host_start_pos)
- or M._make_host(p, host_start_pos)
+ and M._parse_host_with_omit_ssh(p, host_start_pos)
+ or M._parse_host(p, host_start_pos)
return {
user = user,
@@ -398,7 +408,7 @@ M.parse = function(url)
-- protocol end with '://'
local protocol, protocol_pos = M._make(url, 1, protocol_delimiter_pos - 1)
- local user_obj = M._make_user(url, protocol_delimiter_pos + 3)
+ local user_obj = M._parse_user(url, protocol_delimiter_pos + 3)
local host_obj = user_obj.host_obj
local path_obj = host_obj.path_obj
@@ -432,7 +442,7 @@ M.parse = function(url)
-- find first ':', host end position on omitted ssh protocol
local first_colon_pos = M._find(url, ":")
if type(first_colon_pos) == "number" and first_colon_pos > 1 then
- local user_obj = M._make_user(url, 1, true)
+ local user_obj = M._parse_user(url, 1, true)
local host_obj = user_obj.host_obj
local path_obj = host_obj.path_obj
@@ -463,7 +473,7 @@ M.parse = function(url)
-- host not found
-- treat as local file path, either absolute/relative
- local path_obj = M._make_path(url, 1)
+ local path_obj = M._parse_path(url, 1)
return {
-- no protocol
-- no user
diff --git a/version.txt b/version.txt
index 238d6e8..b0f3d96 100644
--- a/version.txt
+++ b/version.txt
@@ -1 +1 @@
-1.0.7
+1.0.8