fix: ip and mac address regex validation (#1758)

* fix: ip and mac address regex validation

* fix quoting/escaping, add migration file

Signed-off-by: invario <67800603+invario@users.noreply.github.com>

---------

Signed-off-by: invario <67800603+invario@users.noreply.github.com>
This commit is contained in:
invario
2026-07-23 13:07:39 -04:00
committed by GitHub
parent 3614f3654b
commit 391b218fe5
2 changed files with 68 additions and 2 deletions

View File

@@ -0,0 +1,62 @@
package migrations
import (
"github.com/pocketbase/pocketbase/core"
m "github.com/pocketbase/pocketbase/migrations"
)
func init() {
m.Register(func(app core.App) error {
collection, err := app.FindCollectionByNameOrId("z5lghx2r3tm45n1")
if err != nil {
return err
}
// update field
if err := collection.Fields.AddMarshaledJSONAt(2, []byte(`{
"autogeneratePattern": "",
"help": "",
"hidden": false,
"id": "1si6ajha",
"max": 0,
"min": 0,
"name": "ip",
"pattern": "^(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}$",
"presentable": false,
"primaryKey": false,
"required": true,
"system": false,
"type": "text"
}`)); err != nil {
return err
}
return app.Save(collection)
}, func(app core.App) error {
collection, err := app.FindCollectionByNameOrId("z5lghx2r3tm45n1")
if err != nil {
return err
}
// update field
if err := collection.Fields.AddMarshaledJSONAt(2, []byte(`{
"autogeneratePattern": "",
"help": "",
"hidden": false,
"id": "1si6ajha",
"max": 0,
"min": 0,
"name": "ip",
"pattern": "^((25[0-5]|(2[0-4]|1\\d|[1-9]|)\\d)\\.?\\b){4}$",
"presentable": false,
"primaryKey": false,
"required": true,
"system": false,
"type": "text"
}`)); err != nil {
return err
}
return app.Save(collection)
})
}

View File

@@ -21,6 +21,10 @@
await getGroups();
});
const ipPattern =
'^(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}$';
const macPattern = '^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$';
async function save() {
// validate crons
if (device.wake_cron_enabled && !(await validateCron(device.wake_cron))) {
@@ -225,7 +229,7 @@
type="text"
placeholder={m.device_general_ip()}
class="input"
pattern="^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b)\{4}$"
pattern={ipPattern}
bind:value={device.ip}
required
/>
@@ -238,7 +242,7 @@
type="text"
placeholder={m.device_general_mac()}
class="input"
pattern="^([0-9\A-Fa-f]{2}[:-]){5}([0-9\A-Fa-f]{2})$"
pattern={macPattern}
bind:value={device.mac}
required
/>