Merge pull request '新建文件不能包含特殊字符:!@\/:"<>|?%' (#305) from caishi/forgeplus-react:gitlink_server into gitlink_server
This commit is contained in:
commit
3c5e10fa58
|
@ -10,7 +10,8 @@ class Index extends Component {
|
||||||
this.state = {
|
this.state = {
|
||||||
editorValue: "",
|
editorValue: "",
|
||||||
filename: "",
|
filename: "",
|
||||||
language: undefined
|
language: undefined,
|
||||||
|
checkName:false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,16 +27,43 @@ class Index extends Component {
|
||||||
};
|
};
|
||||||
|
|
||||||
select_language = (e) => {
|
select_language = (e) => {
|
||||||
console.log(e)
|
|
||||||
this.setState({
|
this.setState({
|
||||||
language: e
|
language: e
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkFileName=(e)=>{
|
||||||
|
let value = (e.target.value);
|
||||||
|
//\需要单独判断
|
||||||
|
const str = '!!@/::"“”<《》>||??%';
|
||||||
|
let reg = /\\/g;
|
||||||
|
if(reg.test(value)){
|
||||||
|
this.setState({
|
||||||
|
checkName:true
|
||||||
|
})
|
||||||
|
}else{
|
||||||
|
for(var i=0;i<str.length;i++){
|
||||||
|
let s = str[i];
|
||||||
|
if(value.indexOf(s) > -1){
|
||||||
|
this.setState({
|
||||||
|
checkName:true
|
||||||
|
})
|
||||||
|
return;
|
||||||
|
}else{
|
||||||
|
this.setState({
|
||||||
|
checkName:false
|
||||||
|
})
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { pathname } = this.props.location;
|
const { pathname } = this.props.location;
|
||||||
const { filename, language } = this.state;
|
const { filename, language , checkName } = this.state;
|
||||||
const urlroot = pathname.split("newfile")[1];
|
const urlroot = pathname.split("newfile")[1];
|
||||||
const file_path = `${urlroot}/${filename}`;
|
const file_path = `${urlroot}/${filename}`;
|
||||||
const { projectDetail } = this.props;
|
const { projectDetail } = this.props;
|
||||||
|
@ -47,15 +75,17 @@ class Index extends Component {
|
||||||
新建文件
|
新建文件
|
||||||
</p>
|
</p>
|
||||||
<div>
|
<div>
|
||||||
<div className="grid-item mb20">
|
<div className="grid-item mb30">
|
||||||
<div className="grid-item">
|
<div className="grid-item">
|
||||||
<div className="setInputAddon">
|
<div className={checkName?"setInputAddon red":"setInputAddon"}>
|
||||||
<Input
|
<Input
|
||||||
addonBefore={`/${ projectDetail && projectDetail.identifier }${urlroot}/`}
|
addonBefore={`/${ projectDetail && projectDetail.identifier }${urlroot}/`}
|
||||||
value={filename}
|
value={filename}
|
||||||
onChange={this.changeFileName}
|
onChange={this.changeFileName}
|
||||||
placeholder="命名文件..."
|
placeholder="命名文件..."
|
||||||
|
onBlur={this.checkFileName}
|
||||||
/>
|
/>
|
||||||
|
{checkName ? <p style={{color:"red",position:'absolute'}}>文件名不能包含下列任何字符:\{`!@/:"<>|?%`}</p>:"" }
|
||||||
</div>
|
</div>
|
||||||
<a onClick={this.CancelAddFile} className="color-blue">
|
<a onClick={this.CancelAddFile} className="color-blue">
|
||||||
取消
|
取消
|
||||||
|
@ -74,7 +104,8 @@ class Index extends Component {
|
||||||
content={undefined}
|
content={undefined}
|
||||||
readOnly={false}
|
readOnly={false}
|
||||||
editorType="new"
|
editorType="new"
|
||||||
descName={filename && `Add ${filename}`}
|
descName={filename ? `Add ${filename}`:""}
|
||||||
|
checkName={checkName}
|
||||||
></Meditor>
|
></Meditor>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -63,13 +63,13 @@ class UserSubmitComponent extends Component {
|
||||||
|
|
||||||
// 提交变更
|
// 提交变更
|
||||||
subMitFrom = () => {
|
subMitFrom = () => {
|
||||||
const { filepath, content, editor_type } = this.props;
|
const { filepath, content, editor_type , checkName} = this.props;
|
||||||
const { branch, projectsId , owner } = this.props.match.params;
|
const { branch, projectsId , owner } = this.props.match.params;
|
||||||
const { submitType, filename } = this.state;
|
const { submitType, filename } = this.state;
|
||||||
this.setState({ isSpin: true });
|
this.setState({ isSpin: true });
|
||||||
let path = editor_type === "upload" ? filepath : filepath.substr(1);
|
let path = editor_type === "upload" ? filepath : filepath.substr(1);
|
||||||
this.props.form.validateFieldsAndScroll((err, values) => {
|
this.props.form.validateFieldsAndScroll((err, values) => {
|
||||||
if (!err) {
|
if (!err && !checkName) {
|
||||||
const url = `/${owner}/${projectsId}/create_file.json`;
|
const url = `/${owner}/${projectsId}/create_file.json`;
|
||||||
axios.post(url, {
|
axios.post(url, {
|
||||||
filepath: filename ? filename : path,
|
filepath: filename ? filename : path,
|
||||||
|
@ -103,13 +103,13 @@ class UserSubmitComponent extends Component {
|
||||||
// 确认修改文件
|
// 确认修改文件
|
||||||
UpdateFile = () => {
|
UpdateFile = () => {
|
||||||
this.setState({ isSpin: true });
|
this.setState({ isSpin: true });
|
||||||
const { branch, detail, content , currentBranch } = this.props;
|
const { branch, detail, content , currentBranch ,checkName } = this.props;
|
||||||
const { projectsId , owner } = this.props.match.params;
|
const { projectsId , owner } = this.props.match.params;
|
||||||
const { submitType } = this.state;
|
const { submitType } = this.state;
|
||||||
const url = `/${owner}/${projectsId}/update_file.json`;
|
const url = `/${owner}/${projectsId}/update_file.json`;
|
||||||
let b = currentBranch || branch;
|
let b = currentBranch || branch;
|
||||||
this.props.form.validateFieldsAndScroll((err, values) => {
|
this.props.form.validateFieldsAndScroll((err, values) => {
|
||||||
if (!err) {
|
if (!err && !checkName) {
|
||||||
axios
|
axios
|
||||||
.put(url, {
|
.put(url, {
|
||||||
filepath: detail.path,
|
filepath: detail.path,
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
.setInputAddon{
|
.setInputAddon{
|
||||||
width: 350px;
|
width: 350px;
|
||||||
margin-right: 20px;
|
margin-right: 20px;
|
||||||
|
position: relative;
|
||||||
}
|
}
|
||||||
.setInputAddon .ant-input-group-addon{
|
.setInputAddon .ant-input-group-addon{
|
||||||
height: 30px;
|
height: 30px;
|
||||||
|
@ -16,6 +17,13 @@
|
||||||
border: 1px solid #d9d9d9!important;
|
border: 1px solid #d9d9d9!important;
|
||||||
border-right: none!important;
|
border-right: none!important;
|
||||||
}
|
}
|
||||||
|
.setInputAddon.red .ant-input-group-addon{
|
||||||
|
border-color: red!important;
|
||||||
|
}
|
||||||
|
.setInputAddon.red .ant-input-group > .ant-input:last-child{
|
||||||
|
border-color: red!important;
|
||||||
|
border-left-color: #d9d9d9!important;
|
||||||
|
}
|
||||||
.editorBorder .editorBorderBox{
|
.editorBorder .editorBorderBox{
|
||||||
border:1px solid #d0d0d0;
|
border:1px solid #d0d0d0;
|
||||||
border-radius: 2px;
|
border-radius: 2px;
|
||||||
|
|
|
@ -34,7 +34,7 @@ class m_editor extends Component {
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { editorValue , changeValue } = this.state;
|
const { editorValue , changeValue } = this.state;
|
||||||
const { readOnly, editorType, currentBranch , descName } = this.props;
|
const { readOnly, editorType, currentBranch , descName , checkName } = this.props;
|
||||||
const editor_options = {
|
const editor_options = {
|
||||||
lineNumbers: "on",
|
lineNumbers: "on",
|
||||||
lineWrapping: true, //强制换行
|
lineWrapping: true, //强制换行
|
||||||
|
@ -76,6 +76,7 @@ class m_editor extends Component {
|
||||||
editor_type={editorType}
|
editor_type={editorType}
|
||||||
currentBranch={currentBranch}
|
currentBranch={currentBranch}
|
||||||
descName={descName}
|
descName={descName}
|
||||||
|
checkName={checkName}
|
||||||
></UserSubmitComponent>
|
></UserSubmitComponent>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
Loading…
Reference in New Issue