diff --git a/src/admin/Bootstrap.DataAccess/Helper/DictHelper.cs b/src/admin/Bootstrap.DataAccess/Helper/DictHelper.cs index dccd2985..2735908b 100644 --- a/src/admin/Bootstrap.DataAccess/Helper/DictHelper.cs +++ b/src/admin/Bootstrap.DataAccess/Helper/DictHelper.cs @@ -169,7 +169,9 @@ namespace Bootstrap.DataAccess { Category = "网站设置", Name = cache[i.Name], - Code = i.Code + + // 后台网站配置不能以 / 号结尾 + Code = i.Name == "AppPath" ? i.Code.TrimEnd('/') : i.Code })); return ret; } @@ -377,6 +379,9 @@ namespace Bootstrap.DataAccess { // dict define == 1 时为新建前台应用 bool ret; + + // 前台网站配置地址 不允许以 / 结尾 + dict.Code = dict.Code.TrimEnd('/'); if (dict.Define == 0) { // Update diff --git a/test/UnitTest/Bootstrap.Admin/Api/SettingsTest.cs b/test/UnitTest/Bootstrap.Admin/Api/SettingsTest.cs index 9aeba955..c7fd7e3e 100644 --- a/test/UnitTest/Bootstrap.Admin/Api/SettingsTest.cs +++ b/test/UnitTest/Bootstrap.Admin/Api/SettingsTest.cs @@ -39,35 +39,68 @@ namespace Bootstrap.Admin.Api var code = DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == "UnitTest-Settings").Code; Assert.Equal("0", code); - // Delete + // Delete ids = DictHelper.RetrieveDicts().Where(d => d.Category == "UnitTest-Settings").Select(d => d.Id); DictHelper.Delete(ids); } + [Fact] + public async void Post_Id_Ok() + { + // Demo + var resp = await Client.PostAsJsonAsync("Demo", new BootstrapDict() { Name = "1", Code = "UnitTest" }); + Assert.False(resp); + + // AppPath + var dict = new BootstrapDict() { Category = "UnitTest", Name = "UnitTest", Code = "http://localhost/AppPath/" }; + resp = await Client.PostAsJsonAsync("AppPath", dict); + Assert.True(resp); + + Assert.Equal(dict.Code.TrimEnd('/'), DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == "应用首页" && d.Name == dict.Name)?.Code ?? ""); + + // update by set dict.Define = 0 + dict.Define = 0; + dict.Code = "http://127.0.0.1/UnitTest"; + resp = await Client.PostAsJsonAsync("AppPath", dict); + Assert.True(resp); + + Assert.Equal(dict.Code.TrimEnd('/'), DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == "应用首页" && d.Name == dict.Name)?.Code ?? ""); + + // del + dict.Name = "UnitTest"; + dict.Code = "UnitTest"; + resp = await Client.DeleteAsJsonAsync("AppPath", dict); + Assert.True(resp); + + // Else + resp = await Client.PostAsJsonAsync("UnitTest", dict); + Assert.False(resp); + } + internal class CacheCorsItem : ICacheCorsItem { /// - /// + /// /// public bool Enabled { get; set; } /// - /// + /// /// public string Key { get; set; } /// - /// + /// /// public string Url { get; set; } /// - /// + /// /// public string Desc { get; set; } /// - /// + /// /// public bool Self { get; set; } }