File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -158,10 +158,16 @@ export default class CoapServer implements ProtocolServer {
158158 }
159159
160160 private createThingUrlPath ( thing : ExposedThing ) {
161- const urlPath = slugify ( thing . title , { lower : true } ) ;
161+ let urlPath = slugify ( thing . title , { lower : true } ) ;
162162
163+ // avoid URL clashes
163164 if ( this . things . has ( urlPath ) ) {
164- return Helpers . generateUniqueName ( 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+ // avoid URL clashes
272273 if ( this . things . has ( urlPath ) ) {
273- urlPath = Helpers . generateUniqueName ( 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+ // avoid name clashes
161162 if ( this . thingNames . has ( urlPath ) ) {
162- urlPath = Helpers . generateUniqueName ( 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 ) {
Original file line number Diff line number Diff line change @@ -124,6 +124,7 @@ export default class Helpers implements Resolver {
124124 return address ;
125125 }
126126
127+ /** @deprecated see https://github.com/eclipse-thingweb/node-wot/issues/1351 */
127128 public static generateUniqueName ( name : string ) : string {
128129 const suffix = name . match ( / .+ _ ( [ 0 - 9 ] + ) $ / ) ;
129130 if ( suffix !== null ) {
You can’t perform that action at this time.
0 commit comments