libs/cbi: Catch errors while creating named sections
This commit is contained in:
parent
a8c64ef3b0
commit
d8282d382b
4 changed files with 14 additions and 1 deletions
|
@ -566,7 +566,7 @@ function AbstractSection.create(self, section)
|
||||||
local stat
|
local stat
|
||||||
|
|
||||||
if section then
|
if section then
|
||||||
stat = self.map:set(section, nil, self.sectiontype)
|
stat = section:match("^%w+$") and self.map:set(section, nil, self.sectiontype)
|
||||||
else
|
else
|
||||||
section = self.map:add(self.sectiontype)
|
section = self.map:add(self.sectiontype)
|
||||||
stat = section
|
stat = section
|
||||||
|
@ -795,6 +795,9 @@ function TypedSection.parse(self, novld)
|
||||||
|
|
||||||
if name and #name > 0 then
|
if name and #name > 0 then
|
||||||
created = self:create(name) and name
|
created = self:create(name) and name
|
||||||
|
if not created then
|
||||||
|
self.invalid_cts = true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -113,8 +113,12 @@ end
|
||||||
<% if self.anonymous then %>
|
<% if self.anonymous then %>
|
||||||
<input class="cbi-button cbi-button-add" type="submit" value="<%:cbi_add%>" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>" title="<%:cbi_add%>" />
|
<input class="cbi-button cbi-button-add" type="submit" value="<%:cbi_add%>" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>" title="<%:cbi_add%>" />
|
||||||
<% else %>
|
<% else %>
|
||||||
|
<% if self.invalid_cts then -%><div class="cbi-section-error"><% end %>
|
||||||
<input type="text" class="cbi-section-create-name" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>" />
|
<input type="text" class="cbi-section-create-name" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>" />
|
||||||
<input class="cbi-button cbi-button-add" type="submit" value="<%:cbi_add%>" title="<%:cbi_add%>" />
|
<input class="cbi-button cbi-button-add" type="submit" value="<%:cbi_add%>" title="<%:cbi_add%>" />
|
||||||
|
<% if self.invalid_cts then -%>
|
||||||
|
<br /><%:cbi_invalid%></div>
|
||||||
|
<%- end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
|
|
|
@ -45,8 +45,12 @@ $Id$
|
||||||
<% if self.anonymous then -%>
|
<% if self.anonymous then -%>
|
||||||
<input type="submit" class="cbi-button cbi-button-add" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>" value="<%:cbi_add%>" />
|
<input type="submit" class="cbi-button cbi-button-add" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>" value="<%:cbi_add%>" />
|
||||||
<%- else -%>
|
<%- else -%>
|
||||||
|
<% if self.invalid_cts then -%><div class="cbi-section-error"><% end %>
|
||||||
<input type="text" class="cbi-section-create-name" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>" />
|
<input type="text" class="cbi-section-create-name" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>" />
|
||||||
<input type="submit" class="cbi-button cbi-button-add" value="<%:cbi_add%>" />
|
<input type="submit" class="cbi-button cbi-button-add" value="<%:cbi_add%>" />
|
||||||
|
<% if self.invalid_cts then -%>
|
||||||
|
<br /><%:cbi_invalid%></div>
|
||||||
|
<%- end %>
|
||||||
<%- end %>
|
<%- end %>
|
||||||
</div>
|
</div>
|
||||||
<%- end %>
|
<%- end %>
|
||||||
|
|
|
@ -33,6 +33,8 @@ end
|
||||||
function s.create(self, section)
|
function s.create(self, section)
|
||||||
if TypedSection.create(self, section) then
|
if TypedSection.create(self, section) then
|
||||||
created = section
|
created = section
|
||||||
|
else
|
||||||
|
self.invalid_cts = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue