Skip to content

Commit

Permalink
解决Tester框架聊天界面的html注入问题
Browse files Browse the repository at this point in the history
  • Loading branch information
kosaka-bun committed Sep 17, 2022
1 parent d7ccecb commit 137c52d
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 61 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ build/

.idea/
*.iml
.gradle/
.gradle/
/qqrobot-spring-boot-starter/src/main/resources/framework/tester/
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ subprojects {

repositories {
mavenCentral()
mavenLocal()
maven {
url 'https://www.honoka.de/maven-repo/'
}
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,9 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

@Configuration
public class ConditionalBeans {

@Resource
private MessageExecutor messageExecutor;

@Resource
private RobotBeanHolder robotBeanHolder;

@ConditionalOnMissingBean(RobotLogger.class)
@Bean
public DefaultRobotLogger defaultRobotLogger() {
Expand All @@ -28,7 +20,9 @@ public DefaultRobotLogger defaultRobotLogger() {

@ConditionalOnMissingBean(FrameworkCallback.class)
@Bean
public DefaultFrameworkCallback defaultFrameworkCallback() {
public DefaultFrameworkCallback defaultFrameworkCallback(
MessageExecutor messageExecutor,
RobotBeanHolder robotBeanHolder) {
return new DefaultFrameworkCallback(messageExecutor, robotBeanHolder);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,27 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

@Configuration
public class FrameworkBeans {

@Resource
private FrameworkCallback frameworkCallback;

@Resource
private RobotBasicProperties basicProperties;

@Resource
private MiraiProperties miraiProperties;

@Resource
private TesterProperties testerProperties;

@ConditionalOnProperty(prefix = "honoka.qqrobot",
name = "framework", havingValue = "mirai")
@Bean
public MiraiFramework miraiFramework() {
public MiraiFramework miraiFramework(
FrameworkCallback frameworkCallback,
RobotBasicProperties basicProperties,
MiraiProperties miraiProperties) {
return new MiraiFramework(frameworkCallback, basicProperties,
miraiProperties);
}

@ConditionalOnProperty(prefix = "honoka.qqrobot", name = "framework",
havingValue = "tester", matchIfMissing = true)
@Bean
public TesterFramework testerFramework() {
public TesterFramework testerFramework(
FrameworkCallback frameworkCallback,
RobotBasicProperties basicProperties,
TesterProperties testerProperties) {
return new TesterFramework(frameworkCallback, basicProperties,
testerProperties);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ public class TesterConfig {
@Value("${server.port}")
private int serverPort;

@Value("${server.servlet.context-path:}")
private String contextPath;

@Resource
private TesterProperties testerProperties;

public String getTesterUrl() {
return "http://localhost:" + serverPort +
testerProperties.getWebPrefix() +
"/index.html";
return "http://localhost:" + serverPort + contextPath +
testerProperties.getWebPrefix() + "/index.html";
}
}

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

4 changes: 2 additions & 2 deletions qqrobot-spring-boot-starter/web/build.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
rmdir /s /q ..\src\main\resources\framework\tester\web
call npm run build:prod
move .\dist ..\src/main\resources\framework\tester\
cd ..\src/main\resources\framework\tester\
move .\dist ..\src\main\resources\framework\tester\
cd ..\src\main\resources\framework\tester\
ren dist web
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,10 @@ export default {
this.scrollToEnd();
},
translateToHtml(str) {
return str.replace(/ /g, ' ')
return str.replace(/&/g, '&')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/ /g, '&nbsp;')
.replace(/\n/g, '<br />');
},
getImagePath(name) {
Expand Down

0 comments on commit 137c52d

Please sign in to comment.