Skip to content
This repository was archived by the owner on Feb 28, 2020. It is now read-only.

Release 4.5.1 #446

Merged
merged 2 commits into from
Feb 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

<a name="4.5.1"></a>
## [4.5.1](https://github.com/IBM-Swift/generator-swiftserver/compare/4.5.0...4.5.1) (2018-02-07)


### Bug Fixes

* Init special chars bug ([#445](https://github.com/IBM-Swift/generator-swiftserver/issues/445)) ([ca255f1](https://github.com/IBM-Swift/generator-swiftserver/commit/ca255f1))



<a name="4.5.0"></a>
# [4.5.0](https://github.com/IBM-Swift/generator-swiftserver/compare/4.4.0...4.5.0) (2018-02-01)

Expand Down
84 changes: 43 additions & 41 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,46 @@ module.exports = Generator.extend({
initializing: {
ensureNotInProject: actions.ensureNotInProject,

initAppName: function () {
// save the initial directory for use by the fromSwagger processing.
this.initialWorkingDir = process.cwd()

this.appname = null // Discard yeoman default appname
this.skipPromptingAppName = false
if (this.options.name) {
// User passed a desired application name as an argument
var validation = validateAppName(this.options.name)
if (validation === true) {
// Desired application name is valid, skip prompting for it
// later
this.appname = this.options.name
this.skipPromptingAppName = true
} else {
// Log reason for validation failure, if provided
validation = validation || 'Application name not valid'
debug(this.options.name, ' is not valid because ', validation)
this.log(validation)
}
}

if (this.appname === null) {
// Fall back to name of current working directory
// Normalize if it contains special characters
var sanitizedCWD = path.basename(process.cwd()).replace(/[/@\s+%:.;,?&=+$]+?/g, '-')
// SanitizedCWD replaces /@\s+%:.;,?&=+$ with dashes.
// if the name still contains characters which
// are not encodable by encodeURIComponent, default to 'app'
if (validateAppName(sanitizedCWD) === true) {
this.appname = sanitizedCWD
} else {
// Fall back again to a known valid name
this.log('Failed to produce a valid application name from the current working directory')
debug(sanitizedCWD, ' is not a valid application name and defaulting to \'app\'')
this.appname = 'app'
}
}
},

initSpec: function () {
function isTrue (value) {
return (value === true || value === 'true')
Expand Down Expand Up @@ -107,6 +147,9 @@ module.exports = Generator.extend({
} else if (this.options.init) {
// User passed the --init flag, so no prompts, just generate basic default scaffold
this.destinationSet = true
if (this.appname !== path.basename(this.destinationRoot())) {
this.destinationRoot(path.resolve(this.appname))
}
this.skipPrompting = true
this.appPattern = 'Basic'
this.spec = {
Expand All @@ -126,47 +169,6 @@ module.exports = Generator.extend({
}
},

initAppName: function () {
if (this.skipPrompting) return

// save the initial directory for use by the fromSwagger processing.
this.initialWorkingDir = process.cwd()

this.appname = null // Discard yeoman default appname
this.skipPromptingAppName = false
if (this.options.name) {
// User passed a desired application name as an argument
var validation = validateAppName(this.options.name)
if (validation === true) {
// Desired application name is valid, skip prompting for it
// later
this.appname = this.options.name
this.skipPromptingAppName = true
} else {
// Log reason for validation failure, if provided
validation = validation || 'Application name not valid'
debug(this.options.name, ' is not valid because ', validation)
this.log(validation)
}
}

if (this.appname === null) {
// Fall back to name of current working directory
// Normalize if it contains special characters
var sanitizedCWD = path.basename(process.cwd()).replace(/[/@\s+%:.]+?/g, '-')
// We hope that sanitizedCWD is always valid, but check just
// in case it isn't
if (validateAppName(sanitizedCWD) === true) {
this.appname = sanitizedCWD
} else {
// Fall back again to a known valid name
this.log('Failed to produce a valid application name from the current working directory')
debug(sanitizedCWD, ' is not a valid application name and defaulting to \'app\'')
this.appname = 'app'
}
}
},

initForPrompting: function () {
if (this.skipPrompting) return
// initialize for prompting
Expand Down
8 changes: 4 additions & 4 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ exports.validateDirName = function (name) {
if (!name) {
return 'Name is required'
}
return validateValue(name, /[/@\s+%:]/)
return validateValue(name, /[/@\s+%:.;,?&=+$]/)
}

exports.validateRequiredCredential = function (name) {
Expand Down Expand Up @@ -120,7 +120,7 @@ exports.validateAppName = function (name) {
if (name.toLowerCase() === 'favicon.ico') {
return format('Application name cannot be {favicon.ico}')
}
return validateValue(name, /[/@\s+%:]/)
return validateValue(name, /[/@\s+%:.;,?&=+$]/)
}

/**
Expand Down Expand Up @@ -206,7 +206,7 @@ exports.validateRequiredName = function (name) {
if (!name) {
return format('Name is required.')
}
return validateValue(name, /[/@\s+%:.]/)
return validateValue(name, /[/@\s+%:.;,?&=+$]/)
}

/*
Expand Down Expand Up @@ -236,7 +236,7 @@ exports.validateNewModel = function (name) {
*/
function validateValue (name, unallowedCharacters) {
if (!unallowedCharacters) {
unallowedCharacters = /[/@\s+%:.]/
unallowedCharacters = /[/@\s+%:.;,?&=+$]/
}
if (name.match(unallowedCharacters)) {
return format('The name %s cannot contain special characters (regex %s)',
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "generator-swiftserver",
"version": "4.5.0",
"version": "4.5.1",
"description": "Generator for Kitura REST webservice servers",
"main": "app/index.js",
"scripts": {
Expand Down
33 changes: 31 additions & 2 deletions test/unit/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,10 +425,10 @@ describe('Unit tests for swiftserver:app', function () {
runContext = helpers.run(appGeneratorPath)
.withGenerators(dependentGenerators)
.inTmpDir(function (tmpDir) {
this.inDir(path.join(tmpDir, 'inva&%*lid'))
this.inDir(path.join(tmpDir, 'inva[%*lid'))
})
.withOptions({ testmode: true })
.withArguments(['inva&%*lid'])
.withArguments(['inva[%*lid'])
return runContext.toPromise()
})

Expand Down Expand Up @@ -502,6 +502,35 @@ describe('Unit tests for swiftserver:app', function () {
}))
})

describe('in dir with invalid and sanitizable name using --init', function () {
var runContext

before(function () {
runContext = helpers.run(appGeneratorPath)
.withGenerators(dependentGenerators)
.inTmpDir(function (tmpDir) {
this.inDir(path.join(tmpDir, 'i-n v&a%l@i$d s.y;m,b?o=l+s'))
})
.withOptions({ testmode: true, init: true })
return runContext.toPromise()
})

after(function () {
runContext.cleanTestDirectory()
})

commonTest.itUsedDestinationDirectory('i-n-v-a-l-i-d-s-y-m-b-o-l-s')

it('created a spec object with appName defaulting to dir and no appDir', function () {
var spec = runContext.generator.spec
var expectedSpec = {
appName: 'i-n-v-a-l-i-d-s-y-m-b-o-l-s',
appDir: undefined
}
assert.objectContent(spec, expectedSpec)
})
})

describe('--enableUsecase specified', function () {
describe('Valid --bluemix flag specified', function () {
var runContext
Expand Down