File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -160,8 +160,14 @@ export default class CoapServer implements ProtocolServer {
160160 private createThingUrlPath ( thing : ExposedThing ) {
161161 let urlPath = slugify ( thing . title , { lower : true } ) ;
162162
163- while ( this . things . has ( urlPath ) ) {
164- urlPath += "_" ;
163+ // avoid URL clashes
164+ if ( this . things . has ( urlPath ) ) {
165+ let uniqueUrlPath ;
166+ let nameClashCnt = 2 ;
167+ do {
168+ uniqueUrlPath = urlPath + "_" + nameClashCnt ++ ;
169+ } while ( this . things . has ( uniqueUrlPath ) ) ;
170+ urlPath = uniqueUrlPath ;
165171 }
166172
167173 return urlPath ;
Original file line number Diff line number Diff line change @@ -269,8 +269,14 @@ export default class HttpServer implements ProtocolServer {
269269 public async expose ( thing : ExposedThing , tdTemplate : WoT . ExposedThingInit = { } ) : Promise < void > {
270270 let urlPath = slugify ( thing . title , { lower : true } ) ;
271271
272- while ( this . things . has ( urlPath ) ) {
273- urlPath += "_" ;
272+ // avoid URL clashes
273+ if ( this . things . has ( urlPath ) ) {
274+ let uniqueUrlPath ;
275+ let nameClashCnt = 2 ;
276+ do {
277+ uniqueUrlPath = urlPath + "_" + nameClashCnt ++ ;
278+ } while ( this . things . has ( uniqueUrlPath ) ) ;
279+ urlPath = uniqueUrlPath ;
274280 }
275281
276282 if ( this . getPort ( ) !== - 1 ) {
Original file line number Diff line number Diff line change @@ -158,8 +158,14 @@ export default class WebSocketServer implements ProtocolServer {
158158 public expose ( thing : ExposedThing ) : Promise < void > {
159159 let urlPath = slugify ( thing . title , { lower : true } ) ;
160160
161- while ( this . thingNames . has ( urlPath ) ) {
162- urlPath += "_" ;
161+ // avoid name clashes
162+ if ( this . thingNames . has ( urlPath ) ) {
163+ let uniqueUrlPath ;
164+ let nameClashCnt = 2 ;
165+ do {
166+ uniqueUrlPath = urlPath + "_" + nameClashCnt ++ ;
167+ } while ( this . thingNames . has ( uniqueUrlPath ) ) ;
168+ urlPath = uniqueUrlPath ;
163169 }
164170
165171 if ( this . getPort ( ) !== - 1 ) {
You can’t perform that action at this time.
0 commit comments