forked from Gitlink/forgeplus-react
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 = {
|
||||
editorValue: "",
|
||||
filename: "",
|
||||
language: undefined
|
||||
language: undefined,
|
||||
checkName:false
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -26,16 +27,43 @@ class Index extends Component {
|
|||
};
|
||||
|
||||
select_language = (e) => {
|
||||
console.log(e)
|
||||
this.setState({
|
||||
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() {
|
||||
const { pathname } = this.props.location;
|
||||
const { filename, language } = this.state;
|
||||
const { filename, language , checkName } = this.state;
|
||||
const urlroot = pathname.split("newfile")[1];
|
||||
const file_path = `${urlroot}/${filename}`;
|
||||
const { projectDetail } = this.props;
|
||||
|
@ -47,15 +75,17 @@ class Index extends Component {
|
|||
新建文件
|
||||
</p>
|
||||
<div>
|
||||
<div className="grid-item mb20">
|
||||
<div className="grid-item mb30">
|
||||
<div className="grid-item">
|
||||
<div className="setInputAddon">
|
||||
<div className={checkName?"setInputAddon red":"setInputAddon"}>
|
||||
<Input
|
||||
addonBefore={`/${ projectDetail && projectDetail.identifier }${urlroot}/`}
|
||||
value={filename}
|
||||
onChange={this.changeFileName}
|
||||
placeholder="命名文件..."
|
||||
onBlur={this.checkFileName}
|
||||
/>
|
||||
{checkName ? <p style={{color:"red",position:'absolute'}}>文件名不能包含下列任何字符:\{`!@/:"<>|?%`}</p>:"" }
|
||||
</div>
|
||||
<a onClick={this.CancelAddFile} className="color-blue">
|
||||
取消
|
||||
|
@ -74,7 +104,8 @@ class Index extends Component {
|
|||
content={undefined}
|
||||
readOnly={false}
|
||||
editorType="new"
|
||||
descName={filename && `Add ${filename}`}
|
||||
descName={filename ? `Add ${filename}`:""}
|
||||
checkName={checkName}
|
||||
></Meditor>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -63,13 +63,13 @@ class UserSubmitComponent extends Component {
|
|||
|
||||
// 提交变更
|
||||
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 { submitType, filename } = this.state;
|
||||
this.setState({ isSpin: true });
|
||||
let path = editor_type === "upload" ? filepath : filepath.substr(1);
|
||||
this.props.form.validateFieldsAndScroll((err, values) => {
|
||||
if (!err) {
|
||||
if (!err && !checkName) {
|
||||
const url = `/${owner}/${projectsId}/create_file.json`;
|
||||
axios.post(url, {
|
||||
filepath: filename ? filename : path,
|
||||
|
@ -103,13 +103,13 @@ class UserSubmitComponent extends Component {
|
|||
// 确认修改文件
|
||||
UpdateFile = () => {
|
||||
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 { submitType } = this.state;
|
||||
const url = `/${owner}/${projectsId}/update_file.json`;
|
||||
let b = currentBranch || branch;
|
||||
this.props.form.validateFieldsAndScroll((err, values) => {
|
||||
if (!err) {
|
||||
if (!err && !checkName) {
|
||||
axios
|
||||
.put(url, {
|
||||
filepath: detail.path,
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
.setInputAddon{
|
||||
width: 350px;
|
||||
margin-right: 20px;
|
||||
position: relative;
|
||||
}
|
||||
.setInputAddon .ant-input-group-addon{
|
||||
height: 30px;
|
||||
|
@ -16,6 +17,13 @@
|
|||
border: 1px solid #d9d9d9!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{
|
||||
border:1px solid #d0d0d0;
|
||||
border-radius: 2px;
|
||||
|
|
|
@ -34,7 +34,7 @@ class m_editor extends Component {
|
|||
|
||||
render() {
|
||||
const { editorValue , changeValue } = this.state;
|
||||
const { readOnly, editorType, currentBranch , descName } = this.props;
|
||||
const { readOnly, editorType, currentBranch , descName , checkName } = this.props;
|
||||
const editor_options = {
|
||||
lineNumbers: "on",
|
||||
lineWrapping: true, //强制换行
|
||||
|
@ -76,6 +76,7 @@ class m_editor extends Component {
|
|||
editor_type={editorType}
|
||||
currentBranch={currentBranch}
|
||||
descName={descName}
|
||||
checkName={checkName}
|
||||
></UserSubmitComponent>
|
||||
</div>
|
||||
)}
|
||||
|
|
Loading…
Reference in New Issue