清理URL字符串

时间:2019-09-24 17:55:36

标签: ruby

说我们有一个字符串

<build>
  <plugins>
    <plugin>
      <artifactId>maven-assembly-plugin</artifactId>
      <configuration>
        <archive>
          <manifest>
            <mainClass>org.codehaus.mojo.Test</mainClass>
           </manifest>
        </archive>
        <descriptorRefs>
          <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
      </configuration>
      <executions>
        <execution>
          <id>make-assembly</id> <!-- this is used for inheritance merges -->
          <phase>package</phase> <!-- bind to the packaging phase -->
          <goals>
            <goal>single</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

很显然,我们从Unix shell知道dialogRef: MatDialogRef<YourComponent>; this.dialogRef = this.matDialog.open(YourComponent, { disableClose: false }); // Child Functionality this.dialogRef.componentInstance.TestFunction() 本质上意味着要上升两个目录。因此,此URL实际上将转到url = "http://example.com/foo/baz/../../." 。我的问题是,给定字符串中的这些../../.个字符,我们如何清理URL字符串以指向实际资源?

例如:

http://example.com/

另一个:

../

请记住,该功能仍然可以接收普通URL(即url = "http://example.com/foo/baz/../../hello.html" url = process(url) url = "http://example.com/hello.html" ),并在没有任何需要清除的地方按原样返回

2 个答案:

答案 0 :(得分:1)

addressable宝石可以做到这一点。

require 'addressable'
Addressable::URI.parse("http://example.com/foo/baz/../../hello.html").normalize.to_s
#=> "http://example.com/hello.html"    

答案 1 :(得分:0)

ngOnInit() {
  this.route.paramMap.subscribe(params => {
    this.product = products[+params.get('productId')];
  });
}