fix(settings): keep the stored port when a port field is cleared (#6121)

* fix(settings): keep the stored port when a port field is cleared

Clearing the panel-port, subscription-port or LDAP-port InputNumber
fired onChange(null), which the handlers coerced to 0; on blur Ant
Design clamped the empty field to min=1 and the next save silently
persisted port 1. For subPort that breaks the generated subscription
links; for webPort it moves the panel itself to port 1 and locks the
admin out until the port is fixed via the x-ui CLI.

Ignore null changes so clearing a port field snaps back to the last
valid value instead of committing a bogus port.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* test(settings): pin cleared port fields to the stored value

Clearing the subscription-port field must not reach updateSetting at
all, while typed ports still pass through unchanged. Pins the fix so a
handler refactor cannot silently reintroduce the clamped port 1.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
PathGao
2026-07-29 02:10:21 +08:00
committed by GitHub
parent 4605f00a15
commit 579acbc669
3 changed files with 33 additions and 3 deletions
@@ -12,6 +12,36 @@ function LocationProbe() {
}
describe('SubscriptionGeneralTab', () => {
it('keeps the stored subscription port when the field is cleared', () => {
const updateSetting = vi.fn();
renderWithProviders(
<MemoryRouter initialEntries={['/settings#subscription']}>
<SubscriptionGeneralTab allSetting={new AllSetting({ subPort: 2096 })} updateSetting={updateSetting} />
</MemoryRouter>,
);
const portInput = screen.getByDisplayValue('2096');
fireEvent.change(portInput, { target: { value: '' } });
fireEvent.blur(portInput);
expect(updateSetting).not.toHaveBeenCalled();
});
it('forwards typed subscription ports unchanged', () => {
const updateSetting = vi.fn();
renderWithProviders(
<MemoryRouter initialEntries={['/settings#subscription']}>
<SubscriptionGeneralTab allSetting={new AllSetting({ subPort: 2096 })} updateSetting={updateSetting} />
</MemoryRouter>,
);
fireEvent.change(screen.getByDisplayValue('2096'), { target: { value: '8443' } });
expect(updateSetting).toHaveBeenCalledWith({ subPort: 8443 });
});
it('uses router navigation to open subscription format settings', () => {
const allSetting = new AllSetting({ subClashEnable: true });